summaryrefslogtreecommitdiff
path: root/django/contrib/staticfiles/storage.py
diff options
context:
space:
mode:
authorGildardo Adrian Maravilla Jacome <gilmrjc@gmail.com>2021-05-31 09:05:36 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-05-31 10:40:21 +0200
commit781b44240a06f0c868254f40f36ce46c927f56d1 (patch)
treecc63cdccfffdb8c762e3ab8089cf5aab80ce02a1 /django/contrib/staticfiles/storage.py
parentd270dd584e0af12fe6229fb712d0704c232dc7e5 (diff)
downloaddjango-781b44240a06f0c868254f40f36ce46c927f56d1.tar.gz
Refs #32319 -- Changed HashedFilesMixin to use named groups in patterns.
Diffstat (limited to 'django/contrib/staticfiles/storage.py')
-rw-r--r--django/contrib/staticfiles/storage.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py
index dfca0f4a2d..e97355831b 100644
--- a/django/contrib/staticfiles/storage.py
+++ b/django/contrib/staticfiles/storage.py
@@ -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