@@ -1122,12 +1122,12 @@ impl<'a> Parser<'a> {
1122
1122
}
1123
1123
}
1124
1124
1125
- let to_match = if ends_with_slash {
1125
+ let segment_before_slash = if ends_with_slash {
1126
1126
& self . serialization [ segment_start..self . serialization . len ( ) - 1 ]
1127
1127
} else {
1128
1128
& self . serialization [ segment_start..self . serialization . len ( ) ]
1129
1129
} ;
1130
- match to_match {
1130
+ match segment_before_slash {
1131
1131
// If buffer is a double-dot path segment, shorten url’s path,
1132
1132
".." | "%2e%2e" | "%2e%2E" | "%2E%2e" | "%2E%2E" | "%2e." | "%2E." | ".%2e"
1133
1133
| ".%2E" => {
@@ -1148,14 +1148,21 @@ impl<'a> Parser<'a> {
1148
1148
}
1149
1149
}
1150
1150
_ => {
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
+ }
1158
1163
}
1164
+ // If url’s host is neither the empty string nor null,
1165
+ // validation error, set url’s host to the empty string.
1159
1166
if * has_host {
1160
1167
self . log_violation ( SyntaxViolation :: FileWithHostAndWindowsDrive ) ;
1161
1168
* has_host = false ; // FIXME account for this in callers
0 commit comments