From 760943d584587899d2ba0390cad20797001e1b96 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 30 Oct 2024 17:12:42 +0000 Subject: [PATCH] LibWeb/CSS: Correct matching of `calc()` against `` This seems to have vanished from the spec, but in any case, we still need it. Without this change we erroneously thought that calculations that match did not match . --- .../css/hsl-with-number-percentage-calc.txt | 1 + .../input/css/hsl-with-number-percentage-calc.html | 13 +++++++++++++ Userland/Libraries/LibWeb/CSS/CSSNumericType.cpp | 7 ++++--- 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/css/hsl-with-number-percentage-calc.txt create mode 100644 Tests/LibWeb/Text/input/css/hsl-with-number-percentage-calc.html diff --git a/Tests/LibWeb/Text/expected/css/hsl-with-number-percentage-calc.txt b/Tests/LibWeb/Text/expected/css/hsl-with-number-percentage-calc.txt new file mode 100644 index 00000000000..0f939ec099e --- /dev/null +++ b/Tests/LibWeb/Text/expected/css/hsl-with-number-percentage-calc.txt @@ -0,0 +1 @@ +rgb(88, 101, 242) diff --git a/Tests/LibWeb/Text/input/css/hsl-with-number-percentage-calc.html b/Tests/LibWeb/Text/input/css/hsl-with-number-percentage-calc.html new file mode 100644 index 00000000000..a34a170a876 --- /dev/null +++ b/Tests/LibWeb/Text/input/css/hsl-with-number-percentage-calc.html @@ -0,0 +1,13 @@ + + + +
Hello
+ diff --git a/Userland/Libraries/LibWeb/CSS/CSSNumericType.cpp b/Userland/Libraries/LibWeb/CSS/CSSNumericType.cpp index 0b52fecff40..53e603ae4c2 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSNumericType.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSNumericType.cpp @@ -350,7 +350,7 @@ bool CSSNumericType::matches_percentage() const auto base_type = static_cast(i); auto type_exponent = exponent(base_type); if (base_type == BaseType::Percent) { - if (!type_exponent.has_value() || type_exponent == 0) + if (type_exponent != 1) return false; } else { if (type_exponent.has_value() && type_exponent != 0) @@ -409,8 +409,9 @@ bool CSSNumericType::matches_number_percentage() const auto base_type = static_cast(i); auto type_exponent = exponent(base_type); - if (base_type == BaseType::Percent && type_exponent.has_value() && type_exponent != 0 && type_exponent != 1) { - return false; + if (base_type == BaseType::Percent) { + if (type_exponent.has_value() && type_exponent != 0 && type_exponent != 1) + return false; } else if (type_exponent.has_value() && type_exponent != 0) { return false; }