Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion url/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,8 @@ impl Parser<'_> {
_ => {
// If url’s scheme is "file", url’s path is empty, and buffer is a Windows drive letter, then
if scheme_type.is_file()
&& segment_start == path_start + 1
&& segment_start
== Parser::file_first_segment_start(&self.serialization, path_start)
&& is_windows_drive_letter(segment_before_slash)
{
// Replace the second code point in buffer with U+003A (:).
Expand Down Expand Up @@ -1361,6 +1362,16 @@ impl Parser<'_> {
input
}

/// The offset at which `path[0]` of a `file:` URL begins.
///
/// While a hostless `file:` URL is being parsed the serialization carries a
/// run of slashes at `path_start` rather than a single one, so the first
/// segment does not always begin at `path_start + 1`.
fn file_first_segment_start(serialization: &str, path_start: usize) -> usize {
let path = &serialization[path_start..];
path_start + (path.len() - path.trim_start_matches('/').len())
}

fn last_slash_can_be_removed(serialization: &str, path_start: usize) -> bool {
let url_before_segment = &serialization[..serialization.len() - 1];
if let Some(segment_before_start) = url_before_segment.rfind('/') {
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 @@ -42,7 +42,6 @@
<non-spec:/> set pathname to </..//p>
<non-spec:/> set pathname to <//p>
<non-spec:/.//> set pathname to <p>
<file:///w|/m>
<non-special:opaque ?hi>
<non-special:opaque #hi>
<non-special:opaque \t\t \t#hi>
Expand Down