File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -179,6 +179,7 @@ pub fn default_port(scheme: &str) -> Option<u16> {
179
179
}
180
180
181
181
#[ derive( Clone ) ]
182
+ #[ derive( Debug ) ]
182
183
pub struct Input < ' i > {
183
184
chars : str:: Chars < ' i > ,
184
185
}
@@ -1173,7 +1174,7 @@ impl<'a> Parser<'a> {
1173
1174
) -> Input < ' i > {
1174
1175
// Relative path state
1175
1176
loop {
1176
- let segment_start = self . serialization . len ( ) ;
1177
+ let mut segment_start = self . serialization . len ( ) ;
1177
1178
let mut ends_with_slash = false ;
1178
1179
loop {
1179
1180
let input_before_c = input. clone ( ) ;
@@ -1202,6 +1203,10 @@ impl<'a> Parser<'a> {
1202
1203
}
1203
1204
_ => {
1204
1205
self . check_url_code_point ( c, & input) ;
1206
+ if scheme_type. is_file ( ) && is_normalized_windows_drive_letter ( & self . serialization [ path_start+1 ..] ) {
1207
+ self . serialization . push ( '/' ) ;
1208
+ segment_start += 1 ;
1209
+ }
1205
1210
if self . context == Context :: PathSegmentSetter {
1206
1211
if scheme_type. is_special ( ) {
1207
1212
self . serialization
Original file line number Diff line number Diff line change @@ -1262,3 +1262,26 @@ fn test_authority() {
1262
1262
"%C3%A0lex:%C3%A0lex@xn--lex-8ka.xn--p1ai.example.com"
1263
1263
) ;
1264
1264
}
1265
+
1266
+ #[ test]
1267
+ /// https://github.com/servo/rust-url/issues/838
1268
+ fn test_file_with_drive ( ) {
1269
+ let s1 = "fIlE:p:?../" ;
1270
+ let url = url:: Url :: parse ( s1) . unwrap ( ) ;
1271
+ assert_eq ! ( url. to_string( ) , "file:///p:?../" ) ;
1272
+ assert_eq ! ( url. path( ) , "/p:" ) ;
1273
+
1274
+ let testcases = [
1275
+ ( "a" , "file:///p:/a" ) ,
1276
+ ( "" , "file:///p:?../" ) ,
1277
+ ( "?x" , "file:///p:?x" ) ,
1278
+ ( "." , "file:///p:/" ) ,
1279
+ ( ".." , "file:///p:/" ) ,
1280
+ ( "../" , "file:///p:/" ) ,
1281
+ ] ;
1282
+
1283
+ for case in & testcases {
1284
+ let url2 = url:: Url :: join ( & url, case. 0 ) . unwrap ( ) ;
1285
+ assert_eq ! ( url2. to_string( ) , case. 1 ) ;
1286
+ }
1287
+ }
You can’t perform that action at this time.
0 commit comments