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
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)"
Yeah that is indeed an issue - I think the current implementation is a bit too naive here, but I guess it can be easily extended by bringing in a special kind of value for these bracket expressions.
Parentheses in
calc()
expressions are removed. Repro: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](https://developer.mozilla.org/en-US/docs/Web/CSS/calc()#syntax) it says:
Nested
calc()
s are also removed by AngleSharp.Css as well, yet these are clearly allowed by the spec.This issue causes https://github.com/mganss/HtmlSanitizer/issues/263.