diff --git a/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp b/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp index 5f758712324..aa41229d260 100644 --- a/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp +++ b/Libraries/LibWeb/CSS/CSSFontFaceRule.cpp @@ -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()) { - serialize_a_url(builder, source.local_or_url.get().to_string()); - } else { - builder.appendff("local({})", source.local_or_url.get()); - } + 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()) { diff --git a/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp b/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp index aa3c39fa16e..153b5085ccc 100644 --- a/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp +++ b/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -669,10 +670,28 @@ Vector Parser::parse_font_face_src(TokenStream& compo auto const& first = source_tokens.consume_a_token(); if (first.is_function("local"sv)) { + // local() if (first.function().value.is_empty()) { - continue; + dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @font-face src invalid (`local()` syntax is invalid: no arguments); discarding."); + return {}; } - supported_sources.empend(FlyString { first.function().value.first().to_string() }, Optional {}); + + TokenStream function_tokens { first.function().value }; + function_tokens.discard_whitespace(); + auto font_family = parse_family_name_value(function_tokens); + function_tokens.discard_whitespace(); + if (!font_family || function_tokens.has_next_token()) { + dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @font-face src invalid (`local()` syntax is invalid: `{}`); discarding.", first.function().original_source_text()); + return {}; + } + + if (font_family->is_string()) + supported_sources.empend(font_family->as_string().string_value(), Optional {}); + else if (font_family->is_custom_ident()) + supported_sources.empend(font_family->as_custom_ident().custom_ident(), Optional {}); + else + VERIFY_NOT_REACHED(); + continue; }