LibWeb/CSS: Parse local() font sources more correctly

There were several issues with the previous parsing code, like ignoring
trailing tokens, not handling whitespace, and not requiring the value
to be a `<family-name>`. So, fix all that.

Also correct the serialization code, which didn't call
`serialize_a_string()` previously.
This commit is contained in:
Sam Atkins 2025-03-24 17:20:08 +00:00 committed by Andreas Kling
parent 93a2c9946f
commit 285fbc8f1c
Notes: github-actions[bot] 2025-03-25 07:54:56 +00:00
2 changed files with 30 additions and 7 deletions

View file

@ -65,11 +65,15 @@ String CSSFontFaceRule::serialized() const
// 2. The result of invoking serialize a comma-separated list on performing serialize a URL or serialize a LOCAL for each source on the source list.
serialize_a_comma_separated_list(builder, m_font_face.sources(), [&](StringBuilder& builder, ParsedFontFace::Source source) -> void {
if (source.local_or_url.has<URL::URL>()) {
serialize_a_url(builder, source.local_or_url.get<URL::URL>().to_string());
} else {
builder.appendff("local({})", source.local_or_url.get<FlyString>());
}
source.local_or_url.visit(
[&builder](URL::URL const& url) {
serialize_a_url(builder, url.to_string());
},
[&builder](FlyString const& local) {
// https://drafts.csswg.org/cssom-1/#serialize-a-local
// To serialize a LOCAL means to create a string represented by "local(", followed by the serialization of the LOCAL as a string, followed by ")".
builder.appendff("local({})", serialize_a_string(local));
});
// NOTE: No spec currently exists for format()
if (source.format.has_value()) {