Skip to content

Commit fff8db7

Browse files
committed
updated the drive parsing rules.
1 parent 09d8466 commit fff8db7

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/parser.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,12 +1140,12 @@ impl<'a> Parser<'a> {
11401140
}
11411141
}
11421142

1143-
let to_match = if ends_with_slash {
1143+
let segment_before_slash = if ends_with_slash {
11441144
&self.serialization[segment_start..self.serialization.len() - 1]
11451145
} else {
11461146
&self.serialization[segment_start..self.serialization.len()]
11471147
};
1148-
match to_match {
1148+
match segment_before_slash {
11491149
// If buffer is a double-dot path segment, shorten url’s path,
11501150
".." | "%2e%2e" | "%2e%2E" | "%2E%2e" | "%2E%2E" | "%2e." | "%2E." | ".%2e"
11511151
| ".%2E" => {
@@ -1166,13 +1166,21 @@ impl<'a> Parser<'a> {
11661166
}
11671167
}
11681168
_ => {
1169-
if scheme_type.is_file()
1170-
&& is_windows_drive_letter(&self.serialization[path_start + 1..])
1171-
{
1172-
if self.serialization.ends_with('|') {
1173-
self.serialization.pop();
1174-
self.serialization.push(':');
1169+
// If url’s scheme is "file", url’s path is empty, and buffer is a Windows drive letter, then
1170+
if scheme_type.is_file() && is_windows_drive_letter(segment_before_slash) {
1171+
// Replace the second code point in buffer with U+003A (:).
1172+
if let Some(c) = segment_before_slash.chars().nth(0) {
1173+
let mut drive_letter = "".to_string();
1174+
drive_letter.push(c);
1175+
drive_letter.push(':');
1176+
self.serialization.truncate(segment_start);
1177+
self.serialization.push_str(&drive_letter);
1178+
if ends_with_slash {
1179+
self.serialization.push('/');
1180+
}
11751181
}
1182+
// If url’s host is neither the empty string nor null,
1183+
// validation error, set url’s host to the empty string.
11761184
if *has_host {
11771185
self.log_violation(SyntaxViolation::FileWithHostAndWindowsDrive);
11781186
*has_host = false; // FIXME account for this in callers

0 commit comments

Comments
 (0)