1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 18:47:44 +00:00

LibWeb: Parse and ignore SVG paint fallback color

This commit is contained in:
MacDue 2023-07-30 13:52:30 +01:00 committed by Andreas Kling
parent 439735fd35
commit 109ea418ab

View file

@ -4249,17 +4249,12 @@ ErrorOr<RefPtr<StyleValue>> Parser::parse_paint_value(TokenStream<ComponentValue
{ {
// `<paint> = none | <color> | <url> [none | <color>]? | context-fill | context-stroke` // `<paint> = none | <color> | <url> [none | <color>]? | context-fill | context-stroke`
auto parse_color_or_none = [&]() -> ErrorOr<Optional<RefPtr<StyleValue>>> {
if (auto color = TRY(parse_color_value(tokens.peek_token()))) { if (auto color = TRY(parse_color_value(tokens.peek_token()))) {
(void)tokens.next_token(); (void)tokens.next_token();
return color; return color;
} }
if (auto url = TRY(parse_url_value(tokens.peek_token(), AllowedDataUrlType::Image))) {
// FIXME: Accept `[none | <color>]?`
(void)tokens.next_token();
return url;
}
// NOTE: <color> also accepts identifiers, so we do this identifier check last. // NOTE: <color> also accepts identifiers, so we do this identifier check last.
if (tokens.peek_token().is(Token::Type::Ident)) { if (tokens.peek_token().is(Token::Type::Ident)) {
auto maybe_ident = value_id_from_string(tokens.peek_token().token().ident()); auto maybe_ident = value_id_from_string(tokens.peek_token().token().ident());
@ -4275,6 +4270,24 @@ ErrorOr<RefPtr<StyleValue>> Parser::parse_paint_value(TokenStream<ComponentValue
} }
} }
return OptionalNone {};
};
// FIMXE: Allow context-fill/context-stroke here
if (auto color_or_none = TRY(parse_color_or_none()); color_or_none.has_value())
return *color_or_none;
if (auto url = TRY(parse_url_value(tokens.peek_token()))) {
(void)tokens.next_token();
tokens.skip_whitespace();
if (auto color_or_none = TRY(parse_color_or_none()); color_or_none == nullptr) {
// Fail to parse if the fallback is invalid, but otherwise ignore it.
// FIXME: Use fallback color
return nullptr;
}
return url;
}
return nullptr; return nullptr;
} }