File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,15 @@ pub struct PathSegmentsMut<'a> {
4545pub fn new ( url : & mut Url ) -> PathSegmentsMut {
4646 let after_path = url. take_after_path ( ) ;
4747 let old_after_path_position = to_u32 ( url. serialization . len ( ) ) . unwrap ( ) ;
48- debug_assert ! ( url. byte_at( url. path_start) == b'/' ) ;
48+ // Special urls always have a non empty path
49+ if SchemeType :: from ( url. scheme ( ) ) . is_special ( ) {
50+ debug_assert ! ( url. byte_at( url. path_start) == b'/' ) ;
51+ } else {
52+ debug_assert ! (
53+ url. serialization. len( ) == url. path_start as usize
54+ || url. byte_at( url. path_start) == b'/'
55+ ) ;
56+ }
4957 PathSegmentsMut {
5058 after_first_slash : url. path_start as usize + "/" . len ( ) ,
5159 url,
@@ -212,7 +220,10 @@ impl<'a> PathSegmentsMut<'a> {
212220 if matches ! ( segment, "." | ".." ) {
213221 continue ;
214222 }
215- if parser. serialization . len ( ) > path_start + 1 {
223+ if parser. serialization . len ( ) > path_start + 1
224+ // Non special url's path might still be empty
225+ || parser. serialization . len ( ) == path_start
226+ {
216227 parser. serialization . push ( '/' ) ;
217228 }
218229 let mut has_host = true ; // FIXME account for this?
Original file line number Diff line number Diff line change @@ -413,9 +413,9 @@ fn test_set_host() {
413413 assert_eq ! ( url. as_str( ) , "foobar:/hello" ) ;
414414
415415 let mut url = Url :: parse ( "foo://ș" ) . unwrap ( ) ;
416- assert_eq ! ( url. as_str( ) , "foo://%C8%99/ " ) ;
416+ assert_eq ! ( url. as_str( ) , "foo://%C8%99" ) ;
417417 url. set_host ( Some ( "goșu.ro" ) ) . unwrap ( ) ;
418- assert_eq ! ( url. as_str( ) , "foo://go%C8%99u.ro/ " ) ;
418+ assert_eq ! ( url. as_str( ) , "foo://go%C8%99u.ro" ) ;
419419}
420420
421421#[ test]
You can’t perform that action at this time.
0 commit comments