Skip to content

Commit fd042e0

Browse files
authored
Non-special URLs can have their paths erased (#921)
1 parent 49eea1c commit fd042e0

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

url/src/quirks.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,15 @@ pub fn set_pathname(url: &mut Url, new_pathname: &str) {
279279
&& new_pathname.starts_with('\\'))
280280
{
281281
url.set_path(new_pathname)
282-
} else {
282+
} else if SchemeType::from(url.scheme()).is_special()
283+
|| !new_pathname.is_empty()
284+
|| !url.has_host()
285+
{
283286
let mut path_to_set = String::from("/");
284287
path_to_set.push_str(new_pathname);
285288
url.set_path(&path_to_set)
289+
} else {
290+
url.set_path(new_pathname)
286291
}
287292
}
288293

url/tests/expected_failures.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
<http://example.net:8080/path> set hostname to <example.com:>
3939
<non-spec:/.//p> set hostname to <h>
4040
<non-spec:/.//p> set hostname to <>
41-
<foo://somehost/some/path> set pathname to <>
4241
<foo:///some/path> set pathname to <>
4342
<http://example.net:8080/path> set port to <randomstring>
4443
<file:///var/log/system.log> set href to <http://0300.168.0xF0>

0 commit comments

Comments
 (0)