Browse Source

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.
Sam Atkins 1 năm trước cách đây
mục cha
commit
0634d11318

+ 8 - 0
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" )

+ 22 - 0
Tests/LibWeb/Text/input/css/attr-serialization.html

@@ -0,0 +1,22 @@
+<script src="../include.js"></script>
+<script>
+    test(() => {
+        function serialize(input) {
+            document.body.style.content = input;
+            println(document.body.style.content);
+        }
+
+        serialize('attr(foo)');
+        // FIXME: This should produce `attr(foo)` but doesn't yet.
+        serialize('attr(    foo    )');
+        serialize('attr(foo, "fallback")');
+        // FIXME: This should produce `attr(foo, "fallback")` but doesn't yet.
+        serialize('attr(   foo   ,    "fallback"   )');
+        serialize('attr(foo string)');
+        // FIXME: This should produce `attr(foo string)` but doesn't yet.
+        serialize('attr(  foo   string  )');
+        serialize('attr(foo string, "fallback")');
+        // FIXME: This should produce `attr(foo string, "fallback")` but doesn't yet.
+        serialize('attr(  foo   string  ,   "fallback"  )');
+    });
+</script>

+ 2 - 1
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());