Skip to content

Commit 1aa0d8a

Browse files
committed
Fixed django#18487 -- Made sure that protocol-relative URLs aren't processed by the cached staticfiles storage. Thanks to LukaszBalcerzak for the patch.
1 parent 3047981 commit 1aa0d8a

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

django/contrib/staticfiles/storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def converter(matchobj):
161161
matched, url = matchobj.groups()
162162
# Completely ignore http(s) prefixed URLs,
163163
# fragments and data-uri URLs
164-
if url.startswith(('#', 'http:', 'https:', 'data:')):
164+
if url.startswith(('#', 'http:', 'https:', 'data:', '//')):
165165
return matched
166166
name_parts = name.split(os.sep)
167167
# Using posix normpath here to remove duplicates
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
body {
2+
background: url("#foobar");
3+
background: url("http:foobar");
4+
background: url("https:foobar");
5+
background: url("data:foobar");
6+
background: url("//foobar");
7+
}
8+

tests/regressiontests/staticfiles_tests/tests.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,17 @@ def test_template_tag_simple_content(self):
387387
self.assertNotIn(b"cached/other.css", content)
388388
self.assertIn(b"other.d41d8cd98f00.css", content)
389389

390+
def test_path_ignored_completely(self):
391+
relpath = self.cached_file_path("cached/css/ignored.css")
392+
self.assertEqual(relpath, "cached/css/ignored.6c77f2643390.css")
393+
with storage.staticfiles_storage.open(relpath) as relfile:
394+
content = relfile.read()
395+
self.assertIn(b'#foobar', content)
396+
self.assertIn(b'http:foobar', content)
397+
self.assertIn(b'https:foobar', content)
398+
self.assertIn(b'data:foobar', content)
399+
self.assertIn(b'//foobar', content)
400+
390401
def test_path_with_querystring(self):
391402
relpath = self.cached_file_path("cached/styles.css?spam=eggs")
392403
self.assertEqual(relpath,

0 commit comments

Comments
 (0)