Fixed #37 - Make sure absolute filter works with Windows paths.

This commit is contained in:
Jannis Leidel
2010-09-16 11:44:26 +02:00
parent d741cc3383
commit 062796336f

View File

@@ -11,12 +11,12 @@ URL_PATTERN = re.compile(r'url\(([^\)]+)\)')
class CssAbsoluteFilter(FilterBase): class CssAbsoluteFilter(FilterBase):
def input(self, filename=None, **kwargs): def input(self, filename=None, **kwargs):
media_root = os.path.abspath(settings.MEDIA_ROOT) media_root = os.path.normcase(os.path.abspath(settings.MEDIA_ROOT))
if filename is not None: if filename is not None:
filename = os.path.abspath(filename) filename = os.path.normcase(os.path.abspath(filename))
if not filename or not filename.startswith(media_root): if not filename or not filename.startswith(media_root):
return self.content return self.content
self.media_path = filename[len(media_root):] self.media_path = filename[len(media_root):].replace(os.sep, '/')
self.media_path = self.media_path.lstrip('/') self.media_path = self.media_path.lstrip('/')
self.media_url = settings.MEDIA_URL.rstrip('/') self.media_url = settings.MEDIA_URL.rstrip('/')
try: try: