From 3f18331594ee3899f972edd8afeb836cb5dd2d1b Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 15 May 2025 12:57:51 +0100 Subject: [PATCH] LibWeb/HTML: Do not allow named window targeting with noopener Corresponds to https://github.com/whatwg/html/commit/dfdafb4b295f053c207cbba6deb136819501a00c We fail the test for this, but we actually do create the separate popup windows correctly (when popups aren't blocked!) but the test checks `window.name` which we incorrectly return the empty string for. https://wpt.live/html/browsers/windows/auxiliary-browsing-contexts/named-lookup-noopener.html --- Libraries/LibWeb/HTML/Navigable.cpp | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/Libraries/LibWeb/HTML/Navigable.cpp b/Libraries/LibWeb/HTML/Navigable.cpp index 4901648888f..038c86962d7 100644 --- a/Libraries/LibWeb/HTML/Navigable.cpp +++ b/Libraries/LibWeb/HTML/Navigable.cpp @@ -362,17 +362,6 @@ void Navigable::set_ongoing_navigation(Variant ongoing // https://html.spec.whatwg.org/multipage/document-sequences.html#the-rules-for-choosing-a-navigable Navigable::ChosenNavigable Navigable::choose_a_navigable(StringView name, TokenizedFeature::NoOpener no_opener, ActivateTab activate_tab, Optional window_features) { - // NOTE: Implementation for step 7 here. - GC::Ptr navigable_by_target_name = nullptr; - auto find_and_assign_navigable_by_target_name = [&](StringView name) { - auto maybe_navigable = find_a_navigable_by_target_name(name); - if (maybe_navigable) { - navigable_by_target_name = maybe_navigable; - return true; - } - return false; - }; - // 1. Let chosen be null. GC::Ptr chosen = nullptr; @@ -402,16 +391,16 @@ Navigable::ChosenNavigable Navigable::choose_a_navigable(StringView name, Tokeni chosen = traversable_navigable(); } - // 7. Otherwise, if name is not an ASCII case-insensitive match for "_blank", and there exists a navigable that is - // the result of finding a navigable by target name given name and currentNavigable, set chosen to that navigable. - else if (!Infra::is_ascii_case_insensitive_match(name, "_blank"sv) && find_and_assign_navigable_by_target_name(name)) { - chosen = navigable_by_target_name; + // 7. Otherwise, if name is not an ASCII case-insensitive match for "_blank" and noopener is false, then set chosen + // to the result of finding a navigable by target name given name and currentNavigable. + else if (!Infra::is_ascii_case_insensitive_match(name, "_blank"sv) && no_opener == TokenizedFeature::NoOpener::No) { + chosen = find_a_navigable_by_target_name(name); } - // 8. Otherwise, a new top-level traversable is being requested, and what happens depends on the - // user agent's configuration and abilities — it is determined by the rules given for the first - // applicable option from the following list: - else { + // 8. If chosen is null, then a new top-level traversable is being requested, and what happens depends on the user + // agent's configuration and abilities — it is determined by the rules given for the first applicable option + // from the following list: + if (!chosen) { // --> If currentNavigable's active window does not have transient activation and the user agent has been configured to // not show popups (i.e., the user agent has a "popup blocker" enabled) if (active_window() && !active_window()->has_transient_activation() && traversable_navigable()->page().should_block_pop_ups()) {