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)