Skip to content

Very long data URIs disappear from @font-face declaration #76

Closed
@mganss

Description

@mganss

Example code:

var url = "..."; // data: url with length >= 24294 
var html = $@"<style>@font-face {{
font-family: ""MyFont"";
src: url(""{url}"") format('woff');
font-weight: normal;
font-style: normal;
font-display: swap;
}}</style>";

var parser = new HtmlParser(new HtmlParserOptions(), BrowsingContext.New(Configuration.Default.WithCss(new CssParserOptions
{
    IsIncludingUnknownDeclarations = true,
    IsIncludingUnknownRules = true,
    IsToleratingInvalidSelectors = true,
})));
var dom = parser.ParseDocument(html);
var css = ((ICssStyleSheet)dom.StyleSheets[0]).Rules[0].CssText;
// -> @font-face { font-family: "MyFont"; src: ; font-weight: normal; font-style: normal }

This seems to be the root cause of the issue reported in mganss/HtmlSanitizer#66 (comment)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions