Fixed #17865 -- Strip whitespaces from the paths when using the CachedStaticFilesStorage backend.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17696 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel 2012-03-13 03:48:03 +00:00
parent d174216587
commit 7487c74020
3 changed files with 7 additions and 2 deletions

View File

@ -67,7 +67,7 @@ class CachedFilesMixin(object):
def hashed_name(self, name, content=None): def hashed_name(self, name, content=None):
parsed_name = urlsplit(unquote(name)) parsed_name = urlsplit(unquote(name))
clean_name = parsed_name.path clean_name = parsed_name.path.strip()
if content is None: if content is None:
if not self.exists(clean_name): if not self.exists(clean_name):
raise ValueError("The file '%s' could not be found with %r." % raise ValueError("The file '%s' could not be found with %r." %

View File

@ -1 +1,4 @@
@import url("..//cached///styles.css"); @import url("..//cached///styles.css");
body {
background: #d3d6d8 url(img/relative.png );
}

View File

@ -427,11 +427,13 @@ class TestCollectionCachedStorage(BaseCollectionTestCase,
def test_template_tag_denorm(self): def test_template_tag_denorm(self):
relpath = self.cached_file_path("cached/denorm.css") relpath = self.cached_file_path("cached/denorm.css")
self.assertEqual(relpath, "cached/denorm.363de96e9b4b.css") self.assertEqual(relpath, "cached/denorm.c5bd139ad821.css")
with storage.staticfiles_storage.open(relpath) as relfile: with storage.staticfiles_storage.open(relpath) as relfile:
content = relfile.read() content = relfile.read()
self.assertNotIn("..//cached///styles.css", content) self.assertNotIn("..//cached///styles.css", content)
self.assertIn("/static/cached/styles.93b1147e8552.css", content) self.assertIn("/static/cached/styles.93b1147e8552.css", content)
self.assertNotIn("url(img/relative.png )", content)
self.assertIn("/static/cached/img/relative.acae32e4532b.png", content)
def test_template_tag_relative(self): def test_template_tag_relative(self):
relpath = self.cached_file_path("cached/relative.css") relpath = self.cached_file_path("cached/relative.css")