From f110edebd16fc14fb16d31bd1a3627e6ca80776f Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Wed, 11 Dec 2024 21:01:22 +1300 Subject: [PATCH] LibWeb/HTML: Encoding parse a URL when setting a href URL Fixes many WPT encoding regression tests which regressed in fe891727dc264e23d34b877c8b6da4df80b07bc0. --- .../LibWeb/HTML/HTMLHyperlinkElementUtils.cpp | 17 ++++++++++++----- .../HTML/href-iso-2022-jp-url-encoding.txt | 1 + .../HTML/href-iso-2022-jp-url-encoding.html | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/HTML/href-iso-2022-jp-url-encoding.txt create mode 100644 Tests/LibWeb/Text/input/HTML/href-iso-2022-jp-url-encoding.html diff --git a/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp b/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp index 2e823aa2b36..eb0698d2bfe 100644 --- a/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp +++ b/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Andreas Kling + * Copyright (c) 2024, Shannon Booth * * SPDX-License-Identifier: BSD-2-Clause */ @@ -27,17 +28,23 @@ void HTMLHyperlinkElementUtils::reinitialize_url() const // https://html.spec.whatwg.org/multipage/links.html#concept-hyperlink-url-set void HTMLHyperlinkElementUtils::set_the_url() { - // 1. If this element's href content attribute is absent, set this element's url to null. + // 1. Set this element's url to null. + m_url = {}; + + // 2. If this element's href content attribute is absent, then return. auto href_content_attribute = hyperlink_element_utils_href(); if (!href_content_attribute.has_value()) { - m_url = {}; hyperlink_element_utils_element().invalidate_style(DOM::StyleInvalidationReason::HTMLHyperlinkElementHrefChange); return; } - // 2. Otherwise, parse this element's href content attribute value relative to this element's node document. - // If parsing is successful, set this element's url to the result; otherwise, set this element's url to null. - m_url = hyperlink_element_utils_document().parse_url(*href_content_attribute); + // 3. Let url be the result of encoding-parsing a URL given this element's href content attribute's value, relative to this element's node document. + auto url = hyperlink_element_utils_document().encoding_parse_url(*href_content_attribute); + + // 4. If url is not failure, then set this element's url to url. + if (url.is_valid()) + m_url = move(url); + hyperlink_element_utils_element().invalidate_style(DOM::StyleInvalidationReason::HTMLHyperlinkElementHrefChange); } diff --git a/Tests/LibWeb/Text/expected/HTML/href-iso-2022-jp-url-encoding.txt b/Tests/LibWeb/Text/expected/HTML/href-iso-2022-jp-url-encoding.txt new file mode 100644 index 00000000000..b0fdeec0f85 --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/href-iso-2022-jp-url-encoding.txt @@ -0,0 +1 @@ +%26%2319973%3B diff --git a/Tests/LibWeb/Text/input/HTML/href-iso-2022-jp-url-encoding.html b/Tests/LibWeb/Text/input/HTML/href-iso-2022-jp-url-encoding.html new file mode 100644 index 00000000000..29b77f2ef81 --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/href-iso-2022-jp-url-encoding.html @@ -0,0 +1,16 @@ + + + + + + + + +