@@ -2336,6 +2336,7 @@ fn path_to_file_url_segments_windows(
2336
2336
}
2337
2337
let mut components = path. components ( ) ;
2338
2338
2339
+ let host_start = serialization. len ( ) + 1 ;
2339
2340
let host_end;
2340
2341
let host_internal;
2341
2342
match components. next ( ) {
@@ -2362,15 +2363,24 @@ fn path_to_file_url_segments_windows(
2362
2363
_ => return Err ( ( ) ) ,
2363
2364
}
2364
2365
2366
+ let mut path_only_has_prefix = true ;
2365
2367
for component in components {
2366
2368
if component == Component :: RootDir {
2367
2369
continue ;
2368
2370
}
2371
+ path_only_has_prefix = false ;
2369
2372
// FIXME: somehow work with non-unicode?
2370
2373
let component = component. as_os_str ( ) . to_str ( ) . ok_or ( ( ) ) ?;
2371
2374
serialization. push ( '/' ) ;
2372
2375
serialization. extend ( percent_encode ( component. as_bytes ( ) , PATH_SEGMENT ) ) ;
2373
2376
}
2377
+ // A windows drive letter must end with a slash.
2378
+ if serialization. len ( ) > host_start
2379
+ && parser:: is_windows_drive_letter ( & serialization[ host_start..] )
2380
+ && path_only_has_prefix
2381
+ {
2382
+ serialization. push ( '/' ) ;
2383
+ }
2374
2384
Ok ( ( host_end, host_internal) )
2375
2385
}
2376
2386
@@ -2395,6 +2405,14 @@ fn file_url_segments_to_pathbuf(
2395
2405
bytes. push ( b'/' ) ;
2396
2406
bytes. extend ( percent_decode ( segment. as_bytes ( ) ) ) ;
2397
2407
}
2408
+ // A windows drive letter must end with a slash.
2409
+ if bytes. len ( ) > 2 {
2410
+ if matches ! ( bytes[ bytes. len( ) -2 ] , b'a' ..=b'z' | b'A' ..=b'Z' )
2411
+ && matches ! ( bytes[ bytes. len( ) - 1 ] , b':' | b'|' )
2412
+ {
2413
+ bytes. push ( b'/' ) ;
2414
+ }
2415
+ }
2398
2416
let os_str = OsStr :: from_bytes ( & bytes) ;
2399
2417
let path = PathBuf :: from ( os_str) ;
2400
2418
debug_assert ! (
0 commit comments