From 0634d113185f16ed7b26d47f2cb8fe7c218cd5e3 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 19 Sep 2023 20:45:28 +0100 Subject: [PATCH] LibWeb: Stop adding extra whitespace when serializing CSS Functions Otherwise `attr(|name, "fallback")` becomes `attr(| name , "fallback")` The test here is slightly aspirational. There are other rules for serialization we don't follow (like stripping whitespace entirely from many places) so these are marked with FIXMEs. --- .../Text/expected/css/attr-serialization.txt | 8 +++++++ .../Text/input/css/attr-serialization.html | 22 +++++++++++++++++++ .../Libraries/LibWeb/CSS/Parser/Function.cpp | 3 ++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/css/attr-serialization.txt create mode 100644 Tests/LibWeb/Text/input/css/attr-serialization.html diff --git a/Tests/LibWeb/Text/expected/css/attr-serialization.txt b/Tests/LibWeb/Text/expected/css/attr-serialization.txt new file mode 100644 index 00000000000..64022fac20a --- /dev/null +++ b/Tests/LibWeb/Text/expected/css/attr-serialization.txt @@ -0,0 +1,8 @@ +attr(foo) +attr( foo ) +attr(foo, "fallback") +attr( foo , "fallback" ) +attr(foo string) +attr( foo string ) +attr(foo string, "fallback") +attr( foo string , "fallback" ) diff --git a/Tests/LibWeb/Text/input/css/attr-serialization.html b/Tests/LibWeb/Text/input/css/attr-serialization.html new file mode 100644 index 00000000000..f2c77b83be7 --- /dev/null +++ b/Tests/LibWeb/Text/input/css/attr-serialization.html @@ -0,0 +1,22 @@ + + diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Function.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Function.cpp index 5f39f8b3be8..8705bb69234 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Function.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Function.cpp @@ -24,7 +24,8 @@ String Function::to_string() const serialize_an_identifier(builder, m_name); builder.append('('); - builder.join(' ', m_values); + for (auto& item : m_values) + builder.append(item.to_string()); builder.append(')'); return MUST(builder.to_string());