From d22512a0244a7db13a5e2908be9fbf2bfb5b5edd Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 6 Dec 2020 21:21:18 +0100 Subject: [PATCH] LibWeb: Strip and collapse whitespace in document.title I didn't generalize this into a helper since the HTML spec doesn't seem to use this particular algorithm for anything else. This makes the ACID1 test title show up correctly. :^) --- Libraries/LibWeb/DOM/Document.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index 7ef3a418e0..f4d6a0e6f8 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -25,6 +25,7 @@ */ #include +#include #include #include #include @@ -61,6 +62,7 @@ #include #include #include +#include #include namespace Web::DOM { @@ -240,7 +242,21 @@ String Document::title() const if (!title_element) return {}; - return title_element->text_content(); + auto raw_title = title_element->text_content(); + + StringBuilder builder; + bool last_was_space = false; + for (auto code_point : Utf8View(raw_title)) { + if (isspace(code_point)) { + last_was_space = true; + } else { + if (last_was_space && !builder.is_empty()) + builder.append(' '); + builder.append_code_point(code_point); + last_was_space = false; + } + } + return builder.to_string(); } void Document::attach_to_frame(Badge, Frame& frame)