From fd042e003fe583426454001554542ef95538d794 Mon Sep 17 00:00:00 2001 From: DylanOToole2 <154471300+DylanOToole2@users.noreply.github.com> Date: Fri, 5 Apr 2024 14:37:21 -0400 Subject: [PATCH] Non-special URLs can have their paths erased (#921) --- url/src/quirks.rs | 7 ++++++- url/tests/expected_failures.txt | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/url/src/quirks.rs b/url/src/quirks.rs index 3a99e22cf..1f4600c46 100644 --- a/url/src/quirks.rs +++ b/url/src/quirks.rs @@ -279,10 +279,15 @@ pub fn set_pathname(url: &mut Url, new_pathname: &str) { && new_pathname.starts_with('\\')) { url.set_path(new_pathname) - } else { + } else if SchemeType::from(url.scheme()).is_special() + || !new_pathname.is_empty() + || !url.has_host() + { let mut path_to_set = String::from("/"); path_to_set.push_str(new_pathname); url.set_path(&path_to_set) + } else { + url.set_path(new_pathname) } } diff --git a/url/tests/expected_failures.txt b/url/tests/expected_failures.txt index 168a8327f..91145db79 100644 --- a/url/tests/expected_failures.txt +++ b/url/tests/expected_failures.txt @@ -38,7 +38,6 @@ set hostname to set hostname to set hostname to <> - set pathname to <> set pathname to <> set port to set href to