From f1d79483b77cd36fdf7bfce71004ec543e9d254e Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Wed, 23 Apr 2025 17:00:56 +1200 Subject: [PATCH] LibWeb/HTML: Only trim single '#' on Location.hash setter --- Libraries/LibWeb/HTML/Location.cpp | 4 ++-- Libraries/LibWeb/HTML/Location.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Libraries/LibWeb/HTML/Location.cpp b/Libraries/LibWeb/HTML/Location.cpp index f2161f53d19..02f016be28a 100644 --- a/Libraries/LibWeb/HTML/Location.cpp +++ b/Libraries/LibWeb/HTML/Location.cpp @@ -486,7 +486,7 @@ WebIDL::ExceptionOr Location::hash() const } // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-location-hash -WebIDL::ExceptionOr Location::set_hash(String const& value) +WebIDL::ExceptionOr Location::set_hash(StringView value) { // 1. If this's relevant Document is null, then return. auto const relevant_document = this->relevant_document(); @@ -504,7 +504,7 @@ WebIDL::ExceptionOr Location::set_hash(String const& value) auto this_url_fragment = copy_url.fragment().has_value() ? *copy_url.fragment() : String {}; // 5. Let input be the given value with a single leading "#" removed, if any. - auto input = value.bytes_as_string_view().trim("#"sv, TrimMode::Left); + auto input = value.substring_view(value.starts_with('#')); // 6. Set copyURL's fragment to the empty string. copy_url.set_fragment(String {}); diff --git a/Libraries/LibWeb/HTML/Location.h b/Libraries/LibWeb/HTML/Location.h index 07a2ebcfd66..a8ff216ead0 100644 --- a/Libraries/LibWeb/HTML/Location.h +++ b/Libraries/LibWeb/HTML/Location.h @@ -48,7 +48,7 @@ public: WebIDL::ExceptionOr set_search(String const&); WebIDL::ExceptionOr hash() const; - WebIDL::ExceptionOr set_hash(String const&); + WebIDL::ExceptionOr set_hash(StringView); WebIDL::ExceptionOr replace(String const& url); void reload() const;