@@ -1140,12 +1140,12 @@ impl<'a> Parser<'a> {
1140
1140
}
1141
1141
}
1142
1142
1143
- let to_match = if ends_with_slash {
1143
+ let segment_before_slash = if ends_with_slash {
1144
1144
& self . serialization [ segment_start..self . serialization . len ( ) - 1 ]
1145
1145
} else {
1146
1146
& self . serialization [ segment_start..self . serialization . len ( ) ]
1147
1147
} ;
1148
- match to_match {
1148
+ match segment_before_slash {
1149
1149
// If buffer is a double-dot path segment, shorten url’s path,
1150
1150
".." | "%2e%2e" | "%2e%2E" | "%2E%2e" | "%2E%2E" | "%2e." | "%2E." | ".%2e"
1151
1151
| ".%2E" => {
@@ -1166,13 +1166,21 @@ impl<'a> Parser<'a> {
1166
1166
}
1167
1167
}
1168
1168
_ => {
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
+ }
1175
1181
}
1182
+ // If url’s host is neither the empty string nor null,
1183
+ // validation error, set url’s host to the empty string.
1176
1184
if * has_host {
1177
1185
self . log_violation ( SyntaxViolation :: FileWithHostAndWindowsDrive ) ;
1178
1186
* has_host = false ; // FIXME account for this in callers
0 commit comments