Skip to content

Commit

Permalink
Non-special URLs can have their paths erased (#921)
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanOToole2 committed Apr 5, 2024
1 parent 49eea1c commit fd042e0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 6 additions & 1 deletion url/src/quirks.rs
Expand Up @@ -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)
}
}

Expand Down
1 change: 0 additions & 1 deletion url/tests/expected_failures.txt
Expand Up @@ -38,7 +38,6 @@
<http://example.net:8080/path> set hostname to <example.com:>
<non-spec:/.//p> set hostname to <h>
<non-spec:/.//p> set hostname to <>
<foo://somehost/some/path> set pathname to <>
<foo:///some/path> set pathname to <>
<http://example.net:8080/path> set port to <randomstring>
<file:///var/log/system.log> set href to <http://0300.168.0xF0>
Expand Down

0 comments on commit fd042e0

Please sign in to comment.