mirror of
https://github.com/django/django.git
synced 2025-11-17 02:24:22 +00:00
Fixed #26329 -- Support leading slashes and backslashes on static files URLs
This commit is contained in:
parent
8b229b4dbb
commit
fe717900a0
2 changed files with 17 additions and 1 deletions
|
|
@ -178,7 +178,7 @@ class HashedFilesMixin:
|
|||
if urlsplit(clean_name).path.endswith("/"): # don't hash paths
|
||||
hashed_name = name
|
||||
else:
|
||||
args = (clean_name,)
|
||||
args = (self.clean_name(clean_name).lstrip("/"),)
|
||||
if hashed_files is not None:
|
||||
args += (hashed_files,)
|
||||
hashed_name = hashed_name_func(*args)
|
||||
|
|
|
|||
|
|
@ -368,6 +368,22 @@ class TestHashedFiles:
|
|||
self.assertEqual("Post-processing 'nonutf8.css' failed!\n\n", err.getvalue())
|
||||
self.assertPostCondition()
|
||||
|
||||
def test_leading_slash(self):
|
||||
self.assertStaticRenders("/test/file.txt", "/static/test/file.dad0999e4f8f.txt")
|
||||
self.assertStaticRenders(
|
||||
"/test/file.txt", "/static/test/file.dad0999e4f8f.txt", asvar=True
|
||||
)
|
||||
self.assertStaticRenders(
|
||||
"/cached/styles.css", "/static/cached/styles.5e0040571e1a.css"
|
||||
)
|
||||
self.assertStaticRenders("/path/", "/static/path/")
|
||||
self.assertStaticRenders("/path/?query", "/static/path/?query")
|
||||
self.assertPostCondition()
|
||||
|
||||
def test_backslash_separator(self):
|
||||
self.assertStaticRenders(r"test\file.txt", "/static/test/file.dad0999e4f8f.txt")
|
||||
self.assertPostCondition()
|
||||
|
||||
|
||||
@override_settings(
|
||||
STORAGES={
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue