`CssText` adds replacement character
mganss opened this issue · comments
Michael Ganss commented
I'm not entirely sure if this is a bug but it doesn't seem to occur in browsers. The "
is unbalanced in the source so this might trigger the observed behavior.
This was originally reported in mganss/HtmlSanitizer#411
var html = @"<span style=""background-image: var(--urlSpellingErrorV2,url("https://www.example.com/))"">Ipsum</span>";
var conf = Configuration.Default.WithCss(new CssParserOptions
{
IsIncludingUnknownDeclarations = true,
IsIncludingUnknownRules = true,
IsToleratingInvalidSelectors = true,
});
var parser = new HtmlParser(new HtmlParserOptions { IsScripting = true }, BrowsingContext.New(conf));
var dom = parser.ParseDocument(html);
var span = dom.Body.Children[0];
var attr = span.GetAttribute("style"); // -> "background-image: var(--urlSpellingErrorV2,url(\"https://www.example.com/))"
var style = span.GetStyle();
var cssText = style.CssText; // -> "background-image: var(--urlSpellingErrorV2,url(\"https://www.example.com/))\uffff"
Florian Rappl commented
Yes definitely a bug. I'll try to find some time to look into it!
Thanks for reporting.