Skip to content

Minify css: range selector using logical operators results in minification error #180

@MarcelVersteeg

Description

@MarcelVersteeg

Consider a media query of the form @media (width < 250px) or (height < 500px). When minifying this, the error Expected closing parenthesis, found '<' is reported. However, this media query is valid according to this section on the MDN.

For example, the following code produces this error:

<html>
<head>
<style>
@media (width < 250px) or (height < 500px)
{
    body
    {
        background-color: red;
    }
}
</style>
</head>
<body>
Test
</body>
</html>

The stacktrace is as follows:

at WebMarkupMin.Core.GenericHtmlMinifier.WriteError(String category, String message, String filePath, Int32 lineNumber, Int32 columnNumber, String sourceFragment)
         at WebMarkupMin.Core.GenericHtmlMinifier.ProcessEmbeddedStyleContent(MarkupParsingContext context, String content, String contentType)
         at WebMarkupMin.Core.GenericHtmlMinifier.EmbeddedCodeHandler(MarkupParsingContext context, String code)
         at WebMarkupMin.Core.Parsers.HtmlParser.ProcessEmbeddedCode()
         at WebMarkupMin.Core.Parsers.HtmlParser.Parse(String content)
         at WebMarkupMin.Core.GenericHtmlMinifier.Minify(String content, String fileContext, Encoding encoding, Boolean generateStatistics)

The used settings are as follows:

options.CssMinifierFactory = new NUglifyCssMinifierFactory(new NUglifyCssMinificationSettings
        {
            AbbreviateHexColor = true,
            BlocksStartOnSameLine = BlockStart.SameLine,
            ColorNames = CssColor.Hex,
            CommentMode = CssComment.None,
            DecodeEscapes = false,
            IgnoreAllErrors = false,
            IgnoreErrorList = string.Join(',',
                                          CssMinificationIgnoreErrors.Select(e => $@"CSS{(int)e}")),
            IndentSize = 0,
            IndentType = IndentType.Tab,
            LineBreakThreshold = int.MaxValue,
            MinifyExpressions = true,
            OutputMode = OutputMode.SingleLine,
            RemoveEmptyBlocks = true,
            TermSemicolons = false,
            WarningLevel = int.MaxValue
        });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions