From 8dc4f3763ddc343a25f2997b2a334619598df9de Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Sat, 11 Sep 2021 20:48:45 +0100 Subject: [PATCH] LibWeb: Only apply the unitless-length quirk to needed properties Previously, we applied the unitless length quirk to all numbers in quirks mode. Now, we correctly only do so for the set of properties listed in the quirks-mode spec: https://quirks.spec.whatwg.org/#quirky-length-value However, we do not yet prevent this quirk inside CSS expressions (like `calc()`) as the spec directs. --- .../Libraries/LibWeb/CSS/Parser/Parser.cpp | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 7dda1f779b..c03b7ada14 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -1482,26 +1482,30 @@ Optional Parser::parse_length(ParsingContext const& context, StyleCompon type = Length::Type::In; } else if (unit_string.equals_ignoring_case("Q")) { type = Length::Type::Q; - } else if (context.in_quirks_mode()) { - type = Length::Type::Px; + } else { + return {}; } numeric_value = try_parse_float(length_string); - } else if (component_value.is(Token::Type::Number)) { - auto value_string = component_value.token().m_value.string_view(); - if (value_string == "0") { - type = Length::Type::Px; - numeric_value = 0; - } else if (context.in_quirks_mode()) { - type = Length::Type::Px; - numeric_value = try_parse_float(value_string); - } } else if (component_value.is(Token::Type::Percentage)) { type = Length::Type::Percentage; auto value_string = component_value.token().m_value.string_view(); numeric_value = try_parse_float(value_string); } else if (component_value.is(Token::Type::Ident) && component_value.token().ident().equals_ignoring_case("auto")) { return Length::make_auto(); + } else if (component_value.is(Token::Type::Number)) { + auto value_string = component_value.token().m_value.string_view(); + if (value_string == "0") { + type = Length::Type::Px; + numeric_value = 0; + } else if (context.in_quirks_mode() && property_has_quirk(context.current_property_id(), Quirk::UnitlessLength)) { + // https://quirks.spec.whatwg.org/#quirky-length-value + // FIXME: Disallow quirk when inside a CSS sub-expression (like `calc()`) + // "The value must not be supported in arguments to CSS expressions other than the rect() + // expression, and must not be supported in the supports() static method of the CSS interface." + type = Length::Type::Px; + numeric_value = try_parse_float(value_string); + } } if (!numeric_value.has_value())