Skip to content

Commit

Permalink
Non-special URLs can have their paths erased
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanOToole2 committed Apr 2, 2024
1 parent 2a930db commit 9c04fa5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 1 addition & 3 deletions url/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ pub use form_urlencoded;
extern crate serde;

use crate::host::HostInternal;
use crate::parser::{
to_u32, Context, Parser, SchemeType, PATH_SEGMENT, SPECIAL_PATH_SEGMENT, USERINFO,
};
use crate::parser::{to_u32, Context, Parser, SchemeType, PATH_SEGMENT, USERINFO};
use percent_encoding::{percent_decode, percent_encode, utf8_percent_encode};
use std::borrow::Borrow;
use std::cmp;
Expand Down
7 changes: 6 additions & 1 deletion url/src/quirks.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 9c04fa5

Please sign in to comment.