@@ -456,13 +456,15 @@ impl Url {
456
456
457
457
if self . slice ( self . scheme_end + 1 ..) . starts_with ( "//" ) {
458
458
// URL with authority
459
- match self . byte_at ( self . username_end ) {
460
- b':' => {
461
- assert ! ( self . host_start >= self . username_end + 2 ) ;
462
- assert_eq ! ( self . byte_at( self . host_start - 1 ) , b'@' ) ;
459
+ if self . username_end < self . serialization . len ( ) as u32 {
460
+ match self . byte_at ( self . username_end ) {
461
+ b':' => {
462
+ assert ! ( self . host_start >= self . username_end + 2 ) ;
463
+ assert_eq ! ( self . byte_at( self . host_start - 1 ) , b'@' ) ;
464
+ }
465
+ b'@' => assert ! ( self . host_start == self . username_end + 1 ) ,
466
+ _ => assert_eq ! ( self . username_end, self . scheme_end + 3 ) ,
463
467
}
464
- b'@' => assert ! ( self . host_start == self . username_end + 1 ) ,
465
- _ => assert_eq ! ( self . username_end, self . scheme_end + 3 ) ,
466
468
}
467
469
assert ! ( self . host_start >= self . username_end) ;
468
470
assert ! ( self . host_end >= self . host_start) ;
@@ -490,7 +492,12 @@ impl Url {
490
492
Some ( port_str. parse:: <u16 >( ) . expect( "Couldn't parse port?" ) )
491
493
) ;
492
494
}
493
- assert_eq ! ( self . byte_at( self . path_start) , b'/' ) ;
495
+ assert ! (
496
+ self . path_start as usize == self . serialization. len( )
497
+ || self . byte_at( self . path_start) == b'/'
498
+ || self . byte_at( self . path_start) == b'#'
499
+ || self . byte_at( self . path_start) == b'?'
500
+ ) ;
494
501
} else {
495
502
// Anarchist URL (no authority)
496
503
assert_eq ! ( self . username_end, self . scheme_end + 1 ) ;
@@ -501,11 +508,11 @@ impl Url {
501
508
assert_eq ! ( self . path_start, self . scheme_end + 1 ) ;
502
509
}
503
510
if let Some ( start) = self . query_start {
504
- assert ! ( start > self . path_start) ;
511
+ assert ! ( start >= self . path_start) ;
505
512
assert_eq ! ( self . byte_at( start) , b'?' ) ;
506
513
}
507
514
if let Some ( start) = self . fragment_start {
508
- assert ! ( start > self . path_start) ;
515
+ assert ! ( start >= self . path_start) ;
509
516
assert_eq ! ( self . byte_at( start) , b'#' ) ;
510
517
}
511
518
if let ( Some ( query_start) , Some ( fragment_start) ) = ( self . query_start , self . fragment_start ) {
@@ -745,7 +752,10 @@ impl Url {
745
752
pub fn password ( & self ) -> Option < & str > {
746
753
// This ':' is not the one marking a port number since a host can not be empty.
747
754
// (Except for file: URLs, which do not have port numbers.)
748
- if self . has_authority ( ) && self . byte_at ( self . username_end ) == b':' {
755
+ if self . has_authority ( )
756
+ && self . username_end < self . serialization . len ( ) as u32
757
+ && self . byte_at ( self . username_end ) == b':'
758
+ {
749
759
debug_assert ! ( self . byte_at( self . host_start - 1 ) == b'@' ) ;
750
760
Some ( self . slice ( self . username_end + 1 ..self . host_start - 1 ) )
751
761
} else {
@@ -1226,7 +1236,7 @@ impl Url {
1226
1236
if let Some ( input) = fragment {
1227
1237
self . fragment_start = Some ( to_u32 ( self . serialization . len ( ) ) . unwrap ( ) ) ;
1228
1238
self . serialization . push ( '#' ) ;
1229
- self . mutate ( |parser| parser. parse_fragment ( parser:: Input :: new ( input) ) )
1239
+ self . mutate ( |parser| parser. parse_fragment ( parser:: Input :: no_trim ( input) ) )
1230
1240
} else {
1231
1241
self . fragment_start = None
1232
1242
}
@@ -1284,7 +1294,11 @@ impl Url {
1284
1294
let scheme_type = SchemeType :: from ( self . scheme ( ) ) ;
1285
1295
let scheme_end = self . scheme_end ;
1286
1296
self . mutate ( |parser| {
1287
- parser. parse_query ( scheme_type, scheme_end, parser:: Input :: new ( input) )
1297
+ parser. parse_query (
1298
+ scheme_type,
1299
+ scheme_end,
1300
+ parser:: Input :: trim_tab_and_newlines ( input) ,
1301
+ )
1288
1302
} ) ;
1289
1303
}
1290
1304
@@ -1390,8 +1404,12 @@ impl Url {
1390
1404
}
1391
1405
parser. parse_cannot_be_a_base_path ( parser:: Input :: new ( path) ) ;
1392
1406
} else {
1407
+ let path_start = parser. serialization . len ( ) ;
1393
1408
let mut has_host = true ; // FIXME
1394
1409
parser. parse_path_start ( scheme_type, & mut has_host, parser:: Input :: new ( path) ) ;
1410
+ if scheme_type. is_file ( ) {
1411
+ parser:: trim_path ( & mut parser. serialization , path_start) ;
1412
+ }
1395
1413
}
1396
1414
} ) ;
1397
1415
self . restore_after_path ( old_after_path_pos, & after_path) ;
0 commit comments