Skip to content

Commit

Permalink
Merge branch 'servo:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
theskim authored Nov 26, 2024
2 parents f8741dc + 797b2e2 commit ca4b5dc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 55 deletions.
2 changes: 1 addition & 1 deletion url/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

name = "url"
# When updating version, also modify html_root_url in the lib.rs
version = "2.5.3"
version = "2.5.4"
authors = ["The rust-url developers"]

description = "URL library for Rust, based on the WHATWG URL Standard"
Expand Down
56 changes: 2 additions & 54 deletions url/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ url = { version = "2", features = ["debugger_visualizer"] }
*/

#![no_std]
#![doc(html_root_url = "https://docs.rs/url/2.5.3")]
#![doc(html_root_url = "https://docs.rs/url/2.5.4")]
#![cfg_attr(
feature = "debugger_visualizer",
debugger_visualizer(natvis_file = "../../debug_metadata/url.natvis")
Expand Down Expand Up @@ -1757,39 +1757,6 @@ impl Url {
let old_after_path_pos = to_u32(self.serialization.len()).unwrap();
let cannot_be_a_base = self.cannot_be_a_base();
let scheme_type = SchemeType::from(self.scheme());
let mut path_empty = false;

// Check ':' and then see if the next character is '/'
let mut has_host = if let Some(index) = self.serialization.find(":") {
if self.serialization.len() > index + 1
&& self.serialization.as_bytes().get(index + 1) == Some(&b'/')
{
let rest = &self.serialization[(index + ":/".len())..];
let host_part = rest.split('/').next().unwrap_or("");
path_empty = rest.is_empty();
!host_part.is_empty() && !host_part.contains('@')
} else {
false
}
} else {
false
};

// Ensure the path length is greater than 1 to account
// for cases where "/." is already appended from serialization
// If we set path, then we already checked the other two conditions:
// https://url.spec.whatwg.org/#url-serializing
// 1. The host is null
// 2. the first segment of the URL's path is an empty string
if path.len() > 1 {
if let Some(index) = self.serialization.find(":") {
let removal_start = index + ":".len();
if self.serialization[removal_start..].starts_with("/.") {
self.path_start -= "/.".len() as u32;
}
}
}

self.serialization.truncate(self.path_start as usize);
self.mutate(|parser| {
if cannot_be_a_base {
Expand All @@ -1799,33 +1766,14 @@ impl Url {
}
parser.parse_cannot_be_a_base_path(parser::Input::new_no_trim(path));
} else {
let mut has_host = true; // FIXME
parser.parse_path_start(
scheme_type,
&mut has_host,
parser::Input::new_no_trim(path),
);
}
});

// For cases where normalization is applied across both the serialization and the path.
// Append "/." immediately after the scheme (up to ":")
// This is done if three conditions are met.
// https://url.spec.whatwg.org/#url-serializing
// 1. The host is null
// 2. The url's path length is greater than 1
// 3. the first segment of the URL's path is an empty string
if !has_host && path.len() > 1 && path_empty {
if let Some(index) = self.serialization.find(":") {
if self.serialization.len() > index + 2
&& self.serialization.as_bytes().get(index + 1) == Some(&b'/')
&& self.serialization.as_bytes().get(index + 2) == Some(&b'/')
{
self.serialization.insert_str(index + ":".len(), "/.");
self.path_start += "/.".len() as u32;
}
}
}

self.restore_after_path(old_after_path_pos, &after_path);
}

Expand Down
4 changes: 4 additions & 0 deletions url/tests/expected_failures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@
<file://monkey/> set pathname to <\\\\>
<file:///unicorn> set pathname to <//\\/>
<file:///unicorn> set pathname to <//monkey/..//>
<non-spec:/> set pathname to </.//p>
<non-spec:/> set pathname to </..//p>
<non-spec:/> set pathname to <//p>
<non-spec:/.//> set pathname to <p>

0 comments on commit ca4b5dc

Please sign in to comment.