mirror of
https://github.com/lexmount/moli.git
synced 2026-11-20 16:03:35 +00:00
fix(navigation): resolve empty Location URLs against the entry base
Extracted from wpt-misc-fix commit 0a4bc3da81cdc888bb4c316fcb46e9547ca263f4.
This commit is contained in:
@@ -13,11 +13,7 @@ pub(in crate::context_bootstrap) fn resolve_location_navigation_target(
|
||||
url::Url::parse(raw_target.as_deref().unwrap_or(current_href)).ok()
|
||||
}
|
||||
LocationNavigationKind::Assign | LocationNavigationKind::Replace => {
|
||||
let raw_target = raw_target.unwrap_or_default();
|
||||
if raw_target.is_empty() {
|
||||
return url::Url::parse(current_href).ok();
|
||||
}
|
||||
|
||||
let raw_target = raw_target?;
|
||||
if let Ok(absolute) = url::Url::parse(&raw_target) {
|
||||
return Some(absolute);
|
||||
}
|
||||
|
||||
@@ -592,3 +592,35 @@ fn location_hash_empty_fragment_serializes_empty_and_clears_target() {
|
||||
|
||||
assert_eq!(result, "#target/true|true||false|true");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_location_urls_follow_the_live_entry_document_base() {
|
||||
for operation in [
|
||||
"location.href = input",
|
||||
"location.assign(input)",
|
||||
"location.replace(input)",
|
||||
] {
|
||||
let mut vm = new_parsed_test_vm(
|
||||
"https://navigation-base.test/entry/page.html",
|
||||
"<!doctype html><head><base href='/initial/'></head><body></body>",
|
||||
);
|
||||
vm.eval(&format!(
|
||||
r#"
|
||||
const input = {{toString() {{
|
||||
document.querySelector('base').href = '/converted/target.html?q=empty#discard';
|
||||
return '';
|
||||
}}}};
|
||||
{operation};
|
||||
"#
|
||||
))
|
||||
.unwrap();
|
||||
let pending = vm
|
||||
.take_pending_location_navigation_with_seed()
|
||||
.expect("empty URL resolves to a cross-document navigation");
|
||||
assert_eq!(
|
||||
pending.url.as_str(),
|
||||
"https://navigation-base.test/converted/target.html?q=empty",
|
||||
"{operation}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user