Skip to content

Parentheses in calc() expression removed #67

Closed
@mganss

Description

@mganss

Parentheses in calc() expressions are removed. Repro:

var p = new HtmlParser(new HtmlParserOptions(), BrowsingContext.New(new Configuration().WithCss(new CssParserOptions())));
var dom = p.ParseDocument(@"<html><body><div style=""width: calc((600px - 300px) / 2)"">Test</div></body></html>");
var div = dom.QuerySelector("div");
var style = div.GetStyle();
var css = style.CssText; // -> "width: calc(600px - 300px / 2)"

This works in both Chrome and Firefox, yielding 150px instead of 450px for the test case above. Strangely, it seems the spec doesn't allow for parentheses: https://drafts.csswg.org/css-values-3/#calc-notation

OTOH at MDN it says:

You may also use parentheses to establish computation order when needed.

Nested calc()s are also removed by AngleSharp.Css as well, yet these are clearly allowed by the spec.

var p = new HtmlParser(new HtmlParserOptions(), BrowsingContext.New(new Configuration().WithCss(new CssParserOptions())));
var dom = p.ParseDocument(@"<html><body><div style=""width: calc(calc(600px - 300px) / 2)"">Test</div></body></html>");
var div = dom.QuerySelector("div");
var style = div.GetStyle();
var css = style.CssText; // -> "width: calc(600px - 300px / 2)"

This issue causes mganss/HtmlSanitizer#263.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions