Truly independent web browser
LibWeb: Encoding-parse URLs in Location's assign() and replace()
Andreas Kling6535d1c41440
diff --git a/Libraries/LibWeb/HTML/Location.cpp b/Libraries/LibWeb/HTML/Location.cppindex e645b26da9e..f7ba93d3918 100644--- a/Libraries/LibWeb/HTML/Location.cpp+++ b/Libraries/LibWeb/HTML/Location.cpp@@ -20,7 +20,6 @@#include <LibWeb/Bindings/Location.h>#include <LibWeb/Bindings/WrapperWorld.h>#include <LibWeb/DOM/Document.h>-#include <LibWeb/DOMURL/DOMURL.h>#include <LibWeb/HTML/BrowsingContext.h>#include <LibWeb/HTML/CrossOrigin/AbstractOperations.h>#include <LibWeb/HTML/LocalNavigable.h>@@ -753,12 +752,14 @@ WebIDL::ExceptionOr<void> Location::replace(Utf16String const& url)if (!has_relevant_document())return {};- // 2. Parse url relative to the entry settings object. If that failed, throw a "SyntaxError" DOMException.- auto replace_url = DOMURL::parse(url.utf16_view(), entry_settings_object().api_base_url());+ // 2. Let urlRecord be the result of encoding-parsing a URL given url, relative to the entry settings object.+ auto replace_url = entry_settings_object().encoding_parse_url(url.utf16_view());++ // 3. If urlRecord is failure, then throw a "SyntaxError" DOMException.if (!replace_url.has_value())return WebIDL::SyntaxError::create(Utf16String::formatted("Invalid URL '{}'", url));- // 3. Location-object navigate this to the resulting URL record given "replace".+ // 4. Location-object navigate this to urlRecord given "replace".TRY(navigate(replace_url.release_value(), NavigationHistoryBehavior::Replace));return {};@@ -776,12 +777,14 @@ WebIDL::ExceptionOr<void> Location::assign(Utf16String const& url)if (!relevant_document->origin().is_same_origin_domain(entry_settings_object().origin()))return WebIDL::SecurityError::create("Location's relevant document is not same origin-domain with the entry settings object's origin"_utf16);- // 3. Parse url relative to the entry settings object. If that failed, throw a "SyntaxError" DOMException.- auto assign_url = DOMURL::parse(url.utf16_view(), entry_settings_object().api_base_url());+ // 3. Let urlRecord be the result of encoding-parsing a URL given url, relative to the entry settings object.+ auto assign_url = entry_settings_object().encoding_parse_url(url.utf16_view());++ // 4. If urlRecord is failure, then throw a "SyntaxError" DOMException.if (!assign_url.has_value())return WebIDL::SyntaxError::create(Utf16String::formatted("Invalid URL '{}'", url));- // 4. Location-object navigate this to the resulting URL record.+ // 5. Location-object navigate this to urlRecord.TRY(navigate(assign_url.release_value()));return {};diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/history/the-location-interface/location-encoding-parse.txt b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/history/the-location-interface/location-encoding-parse.txtindex 01cab1af6aa..ae1c2d4ad0c 100644--- a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/history/the-location-interface/location-encoding-parse.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/history/the-location-interface/location-encoding-parse.txt@@ -2,8 +2,7 @@ Harness status: OKFound 3 tests-1 Pass-2 Fail-Fail location.replace() should use document encoding (windows-1252)-Fail location.assign() should use document encoding (windows-1252)+3 Pass+Pass location.replace() should use document encoding (windows-1252)+Pass location.assign() should use document encoding (windows-1252)Pass location.href setter should use document encoding (windows-1252)\ No newline at end of file