Opened 12 years ago

Closed 12 years ago

#18050 closed Bug (fixed)

CachedStaticFilesStorage eats @import statement

Reported by: anonymous Owned by: nobody
Component: contrib.staticfiles Version: 1.4
Severity: Normal Keywords: CachedStaticFilesStorage css preprocessing @import
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Input:

@import '../../3rdparty/pt-sans-generated/stylesheet.css';

html, body {
    padding: 0;
    margin: 0;
    background: transparent;
}

Output:

url("../../3rdparty/pt-sans-generated/stylesheet.cc11c6fa559e.css");

html, body {
    padding: 0;
    margin: 0;
    background: transparent;
}

Without @import statement!

Problem located in:

class CachedFilesMixin(object):
    patterns = (
        ("*.css", (
            r"""(url\(['"]{0,1}\s*(.*?)["']{0,1}\))""",
            r"""(@import\s*["']\s*(.*?)["'])""",
        )),
    )

last statement replace whole (@import…) construction with just url(). This quick fix solves a problem:

class FixedCachedFilesMixin(CachedFilesMixin):
    patterns = (
        ("*.css", (
            r"""(url\(['"]{0,1}\s*(.*?)["']{0,1}\))""",
            r"""@import\s*(["']\s*(.*?)["'])""",
            )),
        )


class CachedStaticFilesStorage(CachedFilesMixin, StaticFilesStorage):
    """
    A static file system storage backend which also saves
    hashed copies of the files it saves.
    """
    pass

But it is definitely a serious bug because @import is completely broken by default.

Change History (2)

comment:1 by Jannis Leidel, 12 years ago

Severity: Release blockerNormal
Triage Stage: UnreviewedAccepted

comment:2 by Jannis Leidel <jannis@…>, 12 years ago

Resolution: fixed
Status: newclosed

In [3047981517ffa0c75c97f05446bd0d41865e323b]:

Fixed #18050 -- Fixed a rather glaring bug in the handling of @import statements when using the cached staticfiles storage.

Note: See TracTickets for help on using tickets.
Back to Top