Skip to content

Commit 6dea973

Browse files
committed
updated the drive parsing rules.
1 parent f828688 commit 6dea973

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/parser.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,12 +1122,12 @@ impl<'a> Parser<'a> {
11221122
}
11231123
}
11241124

1125-
let to_match = if ends_with_slash {
1125+
let segment_before_slash = if ends_with_slash {
11261126
&self.serialization[segment_start..self.serialization.len() - 1]
11271127
} else {
11281128
&self.serialization[segment_start..self.serialization.len()]
11291129
};
1130-
match to_match {
1130+
match segment_before_slash {
11311131
// If buffer is a double-dot path segment, shorten url’s path,
11321132
".." | "%2e%2e" | "%2e%2E" | "%2E%2e" | "%2E%2E" | "%2e." | "%2E." | ".%2e"
11331133
| ".%2E" => {
@@ -1148,14 +1148,21 @@ impl<'a> Parser<'a> {
11481148
}
11491149
}
11501150
_ => {
1151-
if scheme_type.is_file()
1152-
//&& path_start + 1 < self.serialization.len()
1153-
&& is_windows_drive_letter(&self.serialization[path_start + 1..])
1154-
{
1155-
if self.serialization.ends_with('|') {
1156-
self.serialization.pop();
1157-
self.serialization.push(':');
1151+
// If url’s scheme is "file", url’s path is empty, and buffer is a Windows drive letter, then
1152+
if scheme_type.is_file() && is_windows_drive_letter(segment_before_slash) {
1153+
// Replace the second code point in buffer with U+003A (:).
1154+
if let Some(c) = segment_before_slash.chars().nth(0) {
1155+
let mut drive_letter = "".to_string();
1156+
drive_letter.push(c);
1157+
drive_letter.push(':');
1158+
self.serialization.truncate(segment_start);
1159+
self.serialization.push_str(&drive_letter);
1160+
if ends_with_slash {
1161+
self.serialization.push('/');
1162+
}
11581163
}
1164+
// If url’s host is neither the empty string nor null,
1165+
// validation error, set url’s host to the empty string.
11591166
if *has_host {
11601167
self.log_violation(SyntaxViolation::FileWithHostAndWindowsDrive);
11611168
*has_host = false; // FIXME account for this in callers

0 commit comments

Comments
 (0)