From 2975d7275d5602f3d2febda435128ee09330fe86 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Sat, 19 Mar 2022 12:16:50 +0000 Subject: [PATCH] LibWeb: Don't serialize hex-colors as identifiers ID selectors need to be serialized as identifiers in the spec, but other hash-values do not. This was causing hex colors that start with a number, like `#54a3ff`, to serialize as `#\35 4a3ff`, which is silly and unnecessary. Selector serialization is done elsewhere, so this case in Token is probably also unnecessary, but there might be situations I haven't thought of where serializing an ID does need to happen while it's still a Token. --- Userland/Libraries/LibWeb/CSS/Parser/Token.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Token.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Token.cpp index a45fcbf4aa..11e64c4599 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Token.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Token.cpp @@ -23,8 +23,15 @@ String Token::to_string() const return String::formatted("{}(", serialize_an_identifier(function())); case Type::AtKeyword: return String::formatted("@{}", serialize_an_identifier(at_keyword())); - case Type::Hash: - return String::formatted("#{}", serialize_an_identifier(hash_value())); + case Type::Hash: { + switch (m_hash_type) { + case HashType::Id: + return String::formatted("#{}", serialize_an_identifier(hash_value())); + case HashType::Unrestricted: + return String::formatted("#{}", hash_value()); + } + VERIFY_NOT_REACHED(); + } case Type::String: return serialize_a_string(string()); case Type::BadString: