File tree 3 files changed +23
-3
lines changed
3 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -2129,7 +2129,7 @@ impl Url {
2129
2129
} else {
2130
2130
self . host_end
2131
2131
} ;
2132
- let suffix = self . slice ( old_suffix_pos..) . to_owned ( ) ;
2132
+ let mut suffix = self . slice ( old_suffix_pos..) . to_owned ( ) ;
2133
2133
self . serialization . truncate ( self . host_start as usize ) ;
2134
2134
if !self . has_authority ( ) {
2135
2135
debug_assert ! ( self . slice( self . scheme_end..self . host_start) == ":" ) ;
@@ -2143,6 +2143,23 @@ impl Url {
2143
2143
self . host_end = to_u32 ( self . serialization . len ( ) ) . unwrap ( ) ;
2144
2144
self . host = host. into ( ) ;
2145
2145
2146
+ // Adjust serialization to switch between host and empty segment
2147
+ if suffix. starts_with ( "/.//" ) {
2148
+ suffix = suffix[ "/." . len ( ) ..] . to_string ( ) ;
2149
+ // pathname should be "//p" not "p" given that the first segment was empty
2150
+ self . path_start -= "//" . len ( ) as u32 ;
2151
+ } else if self . host == HostInternal :: None && suffix. starts_with ( "//" ) {
2152
+ if let Some ( index) = self . serialization . find ( ":" ) {
2153
+ if self . serialization . len ( ) == index + "://" . len ( )
2154
+ && self . serialization . as_bytes ( ) . get ( index + 1 ) == Some ( & b'/' )
2155
+ && self . serialization . as_bytes ( ) . get ( index + 2 ) == Some ( & b'/' )
2156
+ {
2157
+ self . serialization
2158
+ . replace_range ( index..index + "://" . len ( ) , ":/." ) ;
2159
+ }
2160
+ }
2161
+ }
2162
+
2146
2163
if let Some ( new_port) = opt_new_port {
2147
2164
self . port = new_port;
2148
2165
if let Some ( port) = new_port {
Original file line number Diff line number Diff line change 36
36
<file:/.//p>
37
37
<http://example.net/path> set hostname to <example.com:8080>
38
38
<http://example.net:8080/path> set hostname to <example.com:>
39
- <non-spec:/.//p> set hostname to <h>
40
- <non-spec:/.//p> set hostname to <>
41
39
<foo:///some/path> set pathname to <>
42
40
<file:///var/log/system.log> set href to <http://0300.168.0xF0>
43
41
<file://monkey/> set pathname to <\\\\>
Original file line number Diff line number Diff line change @@ -1382,6 +1382,7 @@ fn serde_error_message() {
1382
1382
1383
1383
#[ test]
1384
1384
fn test_can_be_a_base_with_set_path ( ) {
1385
+ use url:: quirks;
1385
1386
let mut url = Url :: parse ( "web+demo:/" ) . unwrap ( ) ;
1386
1387
assert ! ( !url. cannot_be_a_base( ) ) ;
1387
1388
@@ -1396,6 +1397,10 @@ fn test_can_be_a_base_with_set_path() {
1396
1397
assert_eq ! ( segments, vec![ "" , "not-a-host" ] ) ;
1397
1398
1398
1399
assert_eq ! ( url. as_str( ) , "web+demo:/.//not-a-host" ) ;
1400
+ quirks:: set_hostname ( & mut url, "test" ) . unwrap ( ) ;
1401
+ assert_eq ! ( url. as_str( ) , "web+demo://test//not-a-host" ) ;
1402
+ quirks:: set_hostname ( & mut url, "" ) . unwrap ( ) ;
1403
+ assert_eq ! ( url. as_str( ) , "web+demo:/.//not-a-host" ) ;
1399
1404
}
1400
1405
1401
1406
#[ test]
You can’t perform that action at this time.
0 commit comments