diff options
| author | Jannis Leidel <jannis@leidel.info> | 2012-07-08 18:25:12 +0200 |
|---|---|---|
| committer | Jannis Leidel <jannis@leidel.info> | 2012-07-08 18:25:12 +0200 |
| commit | 1aa0d8ac4d3149fad6ebe80834d9e6f83021cf55 (patch) | |
| tree | e3d25975755e1b13735de8bd49cf2973605b0cf5 | |
| parent | 3047981517ffa0c75c97f05446bd0d41865e323b (diff) | |
Fixed #18487 -- Made sure that protocol-relative URLs aren't processed by the cached staticfiles storage. Thanks to LukaszBalcerzak for the patch.
3 files changed, 20 insertions, 1 deletions
diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py index 4a6650b193..47132831eb 100644 --- a/django/contrib/staticfiles/storage.py +++ b/django/contrib/staticfiles/storage.py @@ -161,7 +161,7 @@ class CachedFilesMixin(object): 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 diff --git a/tests/regressiontests/staticfiles_tests/project/documents/cached/css/ignored.css b/tests/regressiontests/staticfiles_tests/project/documents/cached/css/ignored.css new file mode 100644 index 0000000000..fe7b022215 --- /dev/null +++ b/tests/regressiontests/staticfiles_tests/project/documents/cached/css/ignored.css @@ -0,0 +1,8 @@ +body { + background: url("#foobar"); + background: url("http:foobar"); + background: url("https:foobar"); + background: url("data:foobar"); + background: url("//foobar"); +} + diff --git a/tests/regressiontests/staticfiles_tests/tests.py b/tests/regressiontests/staticfiles_tests/tests.py index 9b14c78dc5..812a80a583 100644 --- a/tests/regressiontests/staticfiles_tests/tests.py +++ b/tests/regressiontests/staticfiles_tests/tests.py @@ -387,6 +387,17 @@ class TestCollectionCachedStorage(BaseCollectionTestCase, 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, |
