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.
This commit is contained in:
Sam Atkins 2023-09-19 20:45:28 +01:00 committed by Andreas Kling
parent f31b39ca18
commit 0634d11318
Notes: sideshowbarker 2024-07-18 22:57:59 +09:00
3 changed files with 32 additions and 1 deletions

View File

@ -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" )

View File

@ -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>

View File

@ -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());