summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2011-09-21 15:58:21 +0000
committerJannis Leidel <jannis@leidel.info>2011-09-21 15:58:21 +0000
commiteb5df8e98db5c5592d5f0a0ca4680f9368ed0db5 (patch)
tree6851a5f6f0694232af02e1421dbf39c8f1338e72 /django
parent75199e8f6d96887c10ba79870428e04ed34e1ca5 (diff)
Fixed the relative static file resolution of the CachedStaticFilesStorage backend and the post processing of deeply nested static files.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16862 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/contrib/staticfiles/storage.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py
index a804c5626c..cf0c4a0e3a 100644
--- a/django/contrib/staticfiles/storage.py
+++ b/django/contrib/staticfiles/storage.py
@@ -113,13 +113,22 @@ class CachedFilesMixin(object):
return matched
name_parts = name.split('/')
# Using posix normpath here to remove duplicates
- result = url_parts = posixpath.normpath(url).split('/')
- level = url.count('..')
- if level:
- result = name_parts[:-level - 1] + url_parts[level:]
- elif name_parts[:-1]:
- result = name_parts[:-1] + url_parts[-1:]
- joined_result = '/'.join(result)
+ url = posixpath.normpath(url)
+ url_parts = url.split('/')
+ parent_level, sub_level = url.count('..'), url.count('/')
+ if url.startswith('/'):
+ sub_level -= 1
+ url_parts = url_parts[1:]
+ if parent_level or not url.startswith('/'):
+ start, end = parent_level + 1, parent_level
+ else:
+ if sub_level:
+ if sub_level == 1:
+ parent_level -= 1
+ start, end = parent_level, sub_level - 1
+ else:
+ start, end = 1, sub_level - 1
+ joined_result = '/'.join(name_parts[:-start] + url_parts[end:])
hashed_url = self.url(joined_result, force=True)
# Return the hashed and normalized version to the file
return 'url("%s")' % hashed_url