Commit 074c7b4d by Luke Yu-Po Chen Committed by Timothée Peignier

use os.path.relpath to find the relative path without changing the file name.

Signed-off-by: Timothée Peignier <timothee.peignier@tryphon.org>
parent 456e758e
......@@ -207,7 +207,7 @@ class Compressor(object):
def relative_path(self, absolute_path):
"""Rewrite paths relative to the output stylesheet path"""
compress_root = os.path.normpath(settings.PIPELINE_ROOT)
return os.path.join(os.sep, absolute_path.replace(compress_root, ''))
return os.path.join(os.sep, os.path.relpath(absolute_path, compress_root))
def read_file(self, path):
"""Read file content in binary mode"""
......
......@@ -58,7 +58,18 @@ class PackagerTest(TestCase):
individual_url = packager.individual_url(filename)
self.assertEqual(individual_url,
"http://localhost/static/js/application.js")
def test_periods_safe_individual_url(self):
"""Check that the periods in file names do not get replaced by individual_url when
PIPELINE_ROOT/STATIC_ROOT is not set, such as in development
"""
settings.PIPELINE_ROOT = settings.STATIC_ROOT = settings.MEDIA_ROOT = ""
packager = Packager()
filename = os.path.join(settings.PIPELINE_ROOT, u'js/application.js')
individual_url = packager.individual_url(filename)
self.assertEqual(individual_url,
"http://localhost/static/js/application.js")
def test_external_urls(self):
packager = Packager()
packages = packager.create_packages({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment