From 225ed58f7ea4a88a14f48f5eb6f3373673c9e11e Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Thu, 11 Jan 2024 06:49:07 +0100 Subject: [PATCH] LibWeb/CSS: Resolve NumericCalculationNode to percentage when requested When the caller of NumericCalculationNode::resolve() does not provide a percentage_basis, it expects the method to return a raw percentage value. Fixes crashing on https://discord.com/login --- Tests/LibWeb/Text/expected/css/css-hsl-with-calc.txt | 1 + Tests/LibWeb/Text/input/css/css-hsl-with-calc.html | 11 +++++++++++ .../LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp | 4 +++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/css/css-hsl-with-calc.txt create mode 100644 Tests/LibWeb/Text/input/css/css-hsl-with-calc.html diff --git a/Tests/LibWeb/Text/expected/css/css-hsl-with-calc.txt b/Tests/LibWeb/Text/expected/css/css-hsl-with-calc.txt new file mode 100644 index 0000000000..2c40701e3f --- /dev/null +++ b/Tests/LibWeb/Text/expected/css/css-hsl-with-calc.txt @@ -0,0 +1 @@ + rgb(30, 31, 34) diff --git a/Tests/LibWeb/Text/input/css/css-hsl-with-calc.html b/Tests/LibWeb/Text/input/css/css-hsl-with-calc.html new file mode 100644 index 0000000000..4edd6b9bef --- /dev/null +++ b/Tests/LibWeb/Text/input/css/css-hsl-with-calc.html @@ -0,0 +1,11 @@ + diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp index 5dacf8e27a..cffe10e09b 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp @@ -220,9 +220,11 @@ bool NumericCalculationNode::contains_percentage() const CalculatedStyleValue::CalculationResult NumericCalculationNode::resolve(Optional, CalculatedStyleValue::PercentageBasis const& percentage_basis) const { if (m_value.has()) { + // NOTE: Depending on whether percentage_basis is set, the caller of resolve() is expecting a raw percentage or + // resolved length. return percentage_basis.visit( [&](Empty const&) -> CalculatedStyleValue::CalculationResult { - VERIFY_NOT_REACHED(); + return m_value; }, [&](auto const& value) { return CalculatedStyleValue::CalculationResult(value.percentage_of(m_value.get()));