mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-06 16:19:23 +00:00
LibWeb/HTML: Encoding parse a URL when setting a href URL
Fixes many WPT encoding regression tests which regressed in
fe891727dc
.
This commit is contained in:
parent
a536ee6f31
commit
f110edebd1
Notes:
github-actions[bot]
2024-12-11 08:49:13 +00:00
Author: https://github.com/shannonbooth
Commit: f110edebd1
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2873
Reviewed-by: https://github.com/gmta ✅
3 changed files with 29 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2021, Andreas Kling <andreas@ladybird.org>
|
* Copyright (c) 2021, Andreas Kling <andreas@ladybird.org>
|
||||||
|
* Copyright (c) 2024, Shannon Booth <shannon@ladybird.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* 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
|
// https://html.spec.whatwg.org/multipage/links.html#concept-hyperlink-url-set
|
||||||
void HTMLHyperlinkElementUtils::set_the_url()
|
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();
|
auto href_content_attribute = hyperlink_element_utils_href();
|
||||||
if (!href_content_attribute.has_value()) {
|
if (!href_content_attribute.has_value()) {
|
||||||
m_url = {};
|
|
||||||
hyperlink_element_utils_element().invalidate_style(DOM::StyleInvalidationReason::HTMLHyperlinkElementHrefChange);
|
hyperlink_element_utils_element().invalidate_style(DOM::StyleInvalidationReason::HTMLHyperlinkElementHrefChange);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Otherwise, parse this element's href content attribute value relative to this element's node document.
|
// 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.
|
||||||
// If parsing is successful, set this element's url to the result; otherwise, set this element's url to null.
|
auto url = hyperlink_element_utils_document().encoding_parse_url(*href_content_attribute);
|
||||||
m_url = hyperlink_element_utils_document().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);
|
hyperlink_element_utils_element().invalidate_style(DOM::StyleInvalidationReason::HTMLHyperlinkElementHrefChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
%26%2319973%3B
|
|
@ -0,0 +1,16 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="iso-2022-jp">
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
const input = "\u4E05"; // 丅
|
||||||
|
const a = document.createElement("a");
|
||||||
|
a.href = "https://ladybird.org/?" + input;
|
||||||
|
println(a.search.substr(1));
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body></body>
|
||||||
|
</html>
|
Loading…
Add table
Add a link
Reference in a new issue