From 04802d4554e2be8c59e4fa56af04210338cfff7c Mon Sep 17 00:00:00 2001 From: Richard Antecki Date: Thu, 19 Feb 2015 11:01:55 +1100 Subject: [PATCH] Strip STATIC_URL from start of path before storage lookup to avoid SuspiciousFileOperation exceptions. --- pipeline/compressors/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pipeline/compressors/__init__.py b/pipeline/compressors/__init__.py index 257373fb..641629ff 100644 --- a/pipeline/compressors/__init__.py +++ b/pipeline/compressors/__init__.py @@ -159,6 +159,11 @@ def embeddable(self, path, variant): font = ext in FONT_EXTS if not variant: return False + + # strip STATIC_URL from path + if path.startswith(settings.STATIC_URL): + path = path[len(settings.STATIC_URL):] + if not (re.search(settings.PIPELINE_EMBED_PATH, path.replace('\\', '/')) and self.storage.exists(path)): return False if ext not in EMBED_EXTS: @@ -170,6 +175,11 @@ def embeddable(self, path, variant): def with_data_uri(self, css): def datauri(match): path = match.group(1) + + # strip STATIC_URL from path + if path.startswith(settings.STATIC_URL): + path = path[len(settings.STATIC_URL):] + mime_type = self.mime_type(path) data = self.encoded_content(path) return "url(\"data:%s;charset=utf-8;base64,%s\")" % (mime_type, data)