mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Refs #32319 -- Changed HashedFilesMixin to use named groups in patterns.
This commit is contained in:
parent
d270dd584e
commit
781b44240a
@ -42,15 +42,21 @@ class StaticFilesStorage(FileSystemStorage):
|
||||
|
||||
|
||||
class HashedFilesMixin:
|
||||
default_template = """url("%s")"""
|
||||
default_template = """url("%(url)s")"""
|
||||
max_post_process_passes = 5
|
||||
patterns = (
|
||||
("*.css", (
|
||||
r"""(url\(['"]{0,1}\s*(.*?)["']{0,1}\))""",
|
||||
(r"""(@import\s*["']\s*(.*?)["'])""", """@import url("%s")"""),
|
||||
r"""(?P<matched>url\(['"]{0,1}\s*(?P<url>.*?)["']{0,1}\))""",
|
||||
(
|
||||
r"""(?P<matched>@import\s*["']\s*(?P<url>.*?)["'])""",
|
||||
"""@import url("%(url)s")""",
|
||||
),
|
||||
)),
|
||||
('*.js', (
|
||||
(r'(?m)^(//# (?-i:sourceMappingURL)=(.*))$', '//# sourceMappingURL=%s'),
|
||||
(
|
||||
r'(?P<matched>)^(//# (?-i:sourceMappingURL)=(?P<url>.*))$',
|
||||
'//# sourceMappingURL=%(url)s',
|
||||
),
|
||||
)),
|
||||
)
|
||||
keep_intermediate_files = True
|
||||
@ -163,7 +169,9 @@ class HashedFilesMixin:
|
||||
This requires figuring out which files the matched URL resolves
|
||||
to and calling the url() method of the storage.
|
||||
"""
|
||||
matched, url = matchobj.groups()
|
||||
matches = matchobj.groupdict()
|
||||
matched = matches['matched']
|
||||
url = matches['url']
|
||||
|
||||
# Ignore absolute/protocol-relative and data-uri URLs.
|
||||
if re.match(r'^[a-z]+:', url):
|
||||
@ -199,7 +207,8 @@ class HashedFilesMixin:
|
||||
transformed_url += ('?#' if '?#' in url else '#') + fragment
|
||||
|
||||
# Return the hashed version to the file
|
||||
return template % unquote(transformed_url)
|
||||
matches['url'] = unquote(transformed_url)
|
||||
return template % matches
|
||||
|
||||
return converter
|
||||
|
||||
|
@ -84,7 +84,10 @@ class ExtraPatternsStorage(ManifestStaticFilesStorage):
|
||||
patterns = tuple(ManifestStaticFilesStorage.patterns) + (
|
||||
(
|
||||
"*.js", (
|
||||
(r"""(url\(['"]{0,1}\s*(.*?)["']{0,1}\))""", 'JS_URL("%s")'),
|
||||
(
|
||||
r"""(?P<matched>url\(['"]{0,1}\s*(?P<url>.*?)["']{0,1}\))""",
|
||||
'JS_URL("%(url)s")',
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user