diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2016-02-20 20:54:18 +0100 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2016-02-23 19:34:21 +0100 |
| commit | 706b33fef80b8b0901fdd2e954e5e5ea189a528a (patch) | |
| tree | 291c65ceca049cb3d648a865da2158b2f0fbc289 /tests/staticfiles_tests/test_storage.py | |
| parent | c62807968d7930bfd34afc2036c67921b943592f (diff) | |
Fixed #26249 -- Fixed collectstatic crash for files in STATIC_ROOT referenced by absolute URL.
collectstatic crashed when:
* a hashing static file storage backend was used
* a static file referenced another static file located directly in
STATIC_ROOT (not a subdirectory) with an absolute URL (which must
start with STATIC_URL, which cannot be empty)
It seems to me that the current code reimplements relative path joining
and doesn't handle edge cases correctly. I suspect it assumes that
STATIC_URL is of the form r'/[^/]+/'.
Throwing out that code in favor of the posixpath module makes the logic
easier to follow. Handling absolute paths correctly also becomes easier.
Diffstat (limited to 'tests/staticfiles_tests/test_storage.py')
| -rw-r--r-- | tests/staticfiles_tests/test_storage.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py index f0c69cebe6..9de5a28223 100644 --- a/tests/staticfiles_tests/test_storage.py +++ b/tests/staticfiles_tests/test_storage.py @@ -96,13 +96,26 @@ class TestHashedFiles(object): def test_template_tag_absolute(self): relpath = self.hashed_file_path("cached/absolute.css") - self.assertEqual(relpath, "cached/absolute.ae9ef2716fe3.css") + self.assertEqual(relpath, "cached/absolute.df312c6326e1.css") with storage.staticfiles_storage.open(relpath) as relfile: content = relfile.read() self.assertNotIn(b"/static/cached/styles.css", content) self.assertIn(b"/static/cached/styles.bb84a0240107.css", content) + self.assertNotIn(b"/static/styles_root.css", content) + self.assertIn(b"/static/styles_root.401f2509a628.css", content) self.assertIn(b'/static/cached/img/relative.acae32e4532b.png', content) + def test_template_tag_absolute_root(self): + """ + Like test_template_tag_absolute, but for a file in STATIC_ROOT (#26249). + """ + relpath = self.hashed_file_path("absolute_root.css") + self.assertEqual(relpath, "absolute_root.f864a4d7f083.css") + with storage.staticfiles_storage.open(relpath) as relfile: + content = relfile.read() + self.assertNotIn(b"/static/styles_root.css", content) + self.assertIn(b"/static/styles_root.401f2509a628.css", content) + def test_template_tag_denorm(self): relpath = self.hashed_file_path("cached/denorm.css") self.assertEqual(relpath, "cached/denorm.c5bd139ad821.css") |
