Skip to content

Commit

Permalink
Fixed django#18487 -- Made sure that protocol-relative URLs aren't pr…
Browse files Browse the repository at this point in the history
…ocessed by the cached staticfiles storage. Thanks to LukaszBalcerzak for the patch.
  • Loading branch information
jezdez committed Jul 8, 2012
1 parent 3047981 commit 1aa0d8a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django/contrib/staticfiles/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def converter(matchobj):
matched, url = matchobj.groups()
# Completely ignore http(s) prefixed URLs,
# fragments and data-uri URLs
if url.startswith(('#', 'http:', 'https:', 'data:')):
if url.startswith(('#', 'http:', 'https:', 'data:', '//')):
return matched
name_parts = name.split(os.sep)
# Using posix normpath here to remove duplicates
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
body {
background: url("#foobar");
background: url("http:foobar");
background: url("https:foobar");
background: url("data:foobar");
background: url("//foobar");
}

11 changes: 11 additions & 0 deletions tests/regressiontests/staticfiles_tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,17 @@ def test_template_tag_simple_content(self):
self.assertNotIn(b"cached/other.css", content)
self.assertIn(b"other.d41d8cd98f00.css", content)

def test_path_ignored_completely(self):
relpath = self.cached_file_path("cached/css/ignored.css")
self.assertEqual(relpath, "cached/css/ignored.6c77f2643390.css")
with storage.staticfiles_storage.open(relpath) as relfile:
content = relfile.read()
self.assertIn(b'#foobar', content)
self.assertIn(b'http:foobar', content)
self.assertIn(b'https:foobar', content)
self.assertIn(b'data:foobar', content)
self.assertIn(b'//foobar', content)

def test_path_with_querystring(self):
relpath = self.cached_file_path("cached/styles.css?spam=eggs")
self.assertEqual(relpath,
Expand Down

0 comments on commit 1aa0d8a

Please sign in to comment.