1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 19:37:36 +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,30 +4249,43 @@ 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`
if (auto color = TRY(parse_color_value(tokens.peek_token()))) { auto parse_color_or_none = [&]() -> ErrorOr<Optional<RefPtr<StyleValue>>> {
(void)tokens.next_token(); if (auto color = TRY(parse_color_value(tokens.peek_token()))) {
return color; (void)tokens.next_token();
} return color;
}
if (auto url = TRY(parse_url_value(tokens.peek_token(), AllowedDataUrlType::Image))) { // NOTE: <color> also accepts identifiers, so we do this identifier check last.
// FIXME: Accept `[none | <color>]?` if (tokens.peek_token().is(Token::Type::Ident)) {
(void)tokens.next_token(); auto maybe_ident = value_id_from_string(tokens.peek_token().token().ident());
return url; if (maybe_ident.has_value()) {
} // FIXME: Accept `context-fill` and `context-stroke`
switch (*maybe_ident) {
// NOTE: <color> also accepts identifiers, so we do this identifier check last. case ValueID::None:
if (tokens.peek_token().is(Token::Type::Ident)) { (void)tokens.next_token();
auto maybe_ident = value_id_from_string(tokens.peek_token().token().ident()); return IdentifierStyleValue::create(*maybe_ident);
if (maybe_ident.has_value()) { default:
// FIXME: Accept `context-fill` and `context-stroke` return nullptr;
switch (*maybe_ident) { }
case ValueID::None:
(void)tokens.next_token();
return IdentifierStyleValue::create(*maybe_ident);
default:
return nullptr;
} }
} }
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;