From 758a0cd0f1c646abf6f7d4f01850d3729ad603e0 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Thu, 16 Feb 2012 14:40:32 +0000 Subject: [PATCH] Fixed #17689 -- Stopped the CachedStaticFilesStorage from trying to hash paths that aren't files. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17535 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/staticfiles/storage.py | 17 ++++++++++------- .../regressiontests/staticfiles_tests/tests.py | 4 ++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py index 0293363fc4c..ac83f522eea 100644 --- a/django/contrib/staticfiles/storage.py +++ b/django/contrib/staticfiles/storage.py @@ -105,13 +105,16 @@ class CachedFilesMixin(object): hashed_name, fragment = name, '' else: clean_name, fragment = urldefrag(name) - cache_key = self.cache_key(name) - hashed_name = self.cache.get(cache_key) - if hashed_name is None: - hashed_name = self.hashed_name(clean_name).replace('\\', '/') - # set the cache if there was a miss - # (e.g. if cache server goes down) - self.cache.set(cache_key, hashed_name) + if urlsplit(clean_name).path.endswith('/'): # don't hash paths + hashed_name = name + else: + cache_key = self.cache_key(name) + hashed_name = self.cache.get(cache_key) + if hashed_name is None: + hashed_name = self.hashed_name(clean_name).replace('\\', '/') + # set the cache if there was a miss + # (e.g. if cache server goes down) + self.cache.set(cache_key, hashed_name) final_url = super(CachedFilesMixin, self).url(hashed_name) diff --git a/tests/regressiontests/staticfiles_tests/tests.py b/tests/regressiontests/staticfiles_tests/tests.py index 680027b63c1..9834885fdd9 100644 --- a/tests/regressiontests/staticfiles_tests/tests.py +++ b/tests/regressiontests/staticfiles_tests/tests.py @@ -317,6 +317,10 @@ class TestCollectionCachedStorage(BaseCollectionTestCase, "/static/test/file.ea5bccaf16d5.txt") self.assertStaticRenders("cached/styles.css", "/static/cached/styles.93b1147e8552.css") + self.assertStaticRenders("path/", + "/static/path/") + self.assertStaticRenders("path/?query", + "/static/path/?query") def test_template_tag_simple_content(self): relpath = self.cached_file_path("cached/styles.css")