Commit 3e4557c 1 parent 4018195 commit 3e4557c Copy full SHA for 3e4557c
File tree 2 files changed +15
-4
lines changed
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> {
45
45
pub fn new ( url : & mut Url ) -> PathSegmentsMut {
46
46
let after_path = url. take_after_path ( ) ;
47
47
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
+ }
49
57
PathSegmentsMut {
50
58
after_first_slash : url. path_start as usize + "/" . len ( ) ,
51
59
url : url,
@@ -212,7 +220,10 @@ impl<'a> PathSegmentsMut<'a> {
212
220
if matches ! ( segment, "." | ".." ) {
213
221
continue ;
214
222
}
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
+ {
216
227
parser. serialization . push ( '/' ) ;
217
228
}
218
229
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() {
413
413
assert_eq ! ( url. as_str( ) , "foobar:/hello" ) ;
414
414
415
415
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" ) ;
417
417
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" ) ;
419
419
}
420
420
421
421
#[ test]
You can’t perform that action at this time.
0 commit comments