mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-31 13:48:25 +00:00
LibWeb/HTML: Update get_an_elements_target() to current spec
This commit is contained in:
committed by
Tim Ledbetter
parent
8dfd382e12
commit
9254994687
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user