mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-05 15:49:11 +00:00
LibWeb/HTML: Update get_an_elements_target() to current spec
This commit is contained in:
parent
8dfd382e12
commit
9254994687
Notes:
github-actions[bot]
2025-01-31 17:28:29 +00:00
Author: https://github.com/AtkinsSJ
Commit: 9254994687
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3402
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/shannonbooth
Reviewed-by: https://github.com/tcl3 ✅
5 changed files with 22 additions and 17 deletions
|
@ -907,21 +907,26 @@ Optional<ARIA::Role> HTMLElement::default_role() const
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/semantics.html#get-an-element's-target
|
||||
String HTMLElement::get_an_elements_target() const
|
||||
String HTMLElement::get_an_elements_target(Optional<String> target) const
|
||||
{
|
||||
// To get an element's target, given an a, area, or form element element, run these steps:
|
||||
// To get an element's target, given an a, area, or form element element, and an optional string-or-null target (default null), run these steps:
|
||||
|
||||
// 1. If element has a target attribute, then return that attribute's value.
|
||||
auto maybe_target = attribute(AttributeNames::target);
|
||||
if (maybe_target.has_value())
|
||||
return maybe_target.release_value();
|
||||
// 1. If target is null, then:
|
||||
if (!target.has_value()) {
|
||||
// 1. If element has a target attribute, then set target to that attribute's value.
|
||||
if (auto maybe_target = attribute(AttributeNames::target); maybe_target.has_value()) {
|
||||
target = maybe_target.release_value();
|
||||
}
|
||||
// FIXME: 2. Otherwise, if element's node document contains a base element with a target attribute,
|
||||
// set target to the value of the target attribute of the first such base element.
|
||||
}
|
||||
|
||||
// FIXME: 2. If element's node document contains a base element with a
|
||||
// target attribute, then return the value of the target attribute of the
|
||||
// first such base element.
|
||||
// 2. If target is not null, and contains an ASCII tab or newline and a U+003C (<), then set target to "_blank".
|
||||
if (target.has_value() && target->bytes_as_string_view().contains("\t\n\r"sv) && target->contains('<'))
|
||||
target = "_blank"_string;
|
||||
|
||||
// 3. Return the empty string.
|
||||
return String {};
|
||||
// 3. Return target.
|
||||
return target.value_or({});
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/links.html#get-an-element's-noopener
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue