Ticket #18487: ignore-paths-starting-with-double-slashes.diff

File ignore-paths-starting-with-double-slashes.diff, 2.3 KB (added by Łukasz Balcerzak, 12 years ago)
  • django/contrib/staticfiles/storage.py

    diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py
    index e02fec8..2f3f624 100644
    a b class CachedFilesMixin(object):  
    153153            matched, url = matchobj.groups()
    154154            # Completely ignore http(s) prefixed URLs,
    155155            # fragments and data-uri URLs
    156             if url.startswith(('#', 'http:', 'https:', 'data:')):
     156            if url.startswith(('#', 'http:', 'https:', 'data:', '//')):
    157157                return matched
    158158            name_parts = name.split(os.sep)
    159159            # Using posix normpath here to remove duplicates
  • new file tests/regressiontests/staticfiles_tests/project/documents/cached/css/ignored.css

    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 0000000..fe7b022
    - +  
     1body {
     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

    diff --git a/tests/regressiontests/staticfiles_tests/tests.py b/tests/regressiontests/staticfiles_tests/tests.py
    index 8321fc2..034ddef 100644
    a b class TestCollectionCachedStorage(BaseCollectionTestCase,  
    383383            self.assertNotIn(b"cached/other.css", content)
    384384            self.assertIn(b"other.d41d8cd98f00.css", content)
    385385
     386    def test_path_ignored_completely(self):
     387        relpath = self.cached_file_path("cached/css/ignored.css")
     388        #self.assertEqual(relpath, "cached/css/ignored.75433540b096.css")
     389        with storage.staticfiles_storage.open(relpath) as relfile:
     390            content = relfile.read()
     391            self.assertIn(b'#foobar', content)
     392            self.assertIn(b'http:foobar', content)
     393            self.assertIn(b'https:foobar', content)
     394            self.assertIn(b'data:foobar', content)
     395            self.assertIn(b'//foobar', content)
     396
    386397    def test_path_with_querystring(self):
    387398        relpath = self.cached_file_path("cached/styles.css?spam=eggs")
    388399        self.assertEqual(relpath,
Back to Top