LibWeb/HTML: Only trim single '#' on Location.hash setter

This commit is contained in:
Shannon Booth 2025-04-23 17:00:56 +12:00 committed by Tim Ledbetter
commit f1d79483b7
Notes: github-actions[bot] 2025-04-23 07:25:29 +00:00
2 changed files with 3 additions and 3 deletions

View file

@ -486,7 +486,7 @@ WebIDL::ExceptionOr<String> Location::hash() const
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-location-hash
WebIDL::ExceptionOr<void> Location::set_hash(String const& value)
WebIDL::ExceptionOr<void> 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<void> 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 {});

View file

@ -48,7 +48,7 @@ public:
WebIDL::ExceptionOr<void> set_search(String const&);
WebIDL::ExceptionOr<String> hash() const;
WebIDL::ExceptionOr<void> set_hash(String const&);
WebIDL::ExceptionOr<void> set_hash(StringView);
WebIDL::ExceptionOr<void> replace(String const& url);
void reload() const;