Skip to content

Parentheses in calc() expression removed #67

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

Closed
mganss opened this issue Mar 4, 2021 · 1 comment
Closed

Parentheses in calc() expression removed #67

mganss opened this issue Mar 4, 2021 · 1 comment
Assignees
Milestone

Comments

@mganss
Copy link
Contributor

mganss commented Mar 4, 2021

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.

@mganss mganss added the bug label Mar 4, 2021
@FlorianRappl
Copy link
Contributor

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.

@FlorianRappl FlorianRappl self-assigned this Mar 4, 2021
FlorianRappl added a commit that referenced this issue Apr 21, 2021
@FlorianRappl FlorianRappl added this to the v0.15 milestone Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants