AngleSharp / AngleSharp.Css

:angel: Library to enable support for cascading stylesheets in AngleSharp.

Home Page:https://anglesharp.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Color not parsed correctly if rgb is not all lowercase

mganss opened this issue · comments

var html = @"<p style='color: RGB(0,17,0)'>Text</p>";
var parser = new HtmlParser(new HtmlParserOptions(), BrowsingContext.New(Configuration.Default.WithCss(new CssParserOptions())));
var dom = parser.ParseDocument(html);
var p = dom.QuerySelector("p");
var s = p.GetStyle();
var color = s.GetColor(); // -> ""

Perhaps this occurs because the dictionary here does not use a comparer that ignores case:

private static readonly Dictionary<String, Func<StringSource, Color?>> ColorFunctions = new Dictionary<String, Func<StringSource, Color?>>
{
{ FunctionNames.Rgb, ParseRgba },
{ FunctionNames.Rgba, ParseRgba },
{ FunctionNames.Hsl, ParseHsla },
{ FunctionNames.Hsla, ParseHsla },
{ FunctionNames.Gray, ParseGray },
{ FunctionNames.Hwb, ParseHwba },
{ FunctionNames.Hwba, ParseHwba },
};

This was originally reported as mganss/HtmlSanitizer#340.

It's a good point. Right now everything is case sensitive, but actually function names (and color names) should be case insensitive:

See https://www.w3.org/TR/css-color-4/#resolving-sRGB-values.

Isn't it the other way around, i.e. it should be case insensitive (rgb and RgB are treated the same, case is ignored) and currently it's case sensitive (only lowercase works)?

Isn't it the other way around, i.e. it should be case insensitive (rgb and RgB are treated the same, case is ignored) and currently it's case sensitive (only lowercase works)?

Correct(ed) - that's what I meant.

Landed in devel.