Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip STATIC_URL from start of path to avoid SuspiciousFileOperation during embed #427

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pipeline/compressors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down