File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -1281,6 +1281,16 @@ impl<'a> Parser<'a> {
1281
1281
self . serialization . push_str ( path. trim_start_matches ( '/' ) ) ;
1282
1282
}
1283
1283
1284
+ // This prevents web+demo:/.//not-a-host/ or web+demo:/path/..//not-a-host/,
1285
+ // when parsed and then serialized, from ending up as web+demo://not-a-host/
1286
+ // (they end up as web+demo:/.//not-a-host/).
1287
+ if !* has_host && self . serialization [ path_start..] . starts_with ( "//" ) {
1288
+ // If url’s host is null, url does not have an opaque path,
1289
+ // url’s path’s size is greater than 1, and url’s path[0] is the empty string,
1290
+ // then append U+002F (/) followed by U+002E (.) to output.
1291
+ self . serialization . insert_str ( path_start, "/." ) ;
1292
+ }
1293
+
1284
1294
input
1285
1295
}
1286
1296
Original file line number Diff line number Diff line change @@ -954,6 +954,17 @@ fn no_panic() {
954
954
url:: quirks:: set_hostname ( & mut url, "//eom/datcom/\\ \\ t\\ ://eom/data.cs" ) . unwrap ( ) ;
955
955
}
956
956
957
+ #[ test]
958
+ fn test_null_host_with_leading_empty_path_fragment ( ) {
959
+ // since Note in item 3 of URL serializing in the URL Standard
960
+ // https://url.spec.whatwg.org/#url-serializing
961
+ let url = Url :: parse ( "m:/.//\\ " ) . unwrap ( ) ;
962
+ let encoded = url. as_str ( ) ;
963
+ println ! ( "{url:?}, {encoded:?}" ) ;
964
+ let reparsed = Url :: parse ( encoded) . unwrap ( ) ;
965
+ assert_eq ! ( reparsed, url) ;
966
+ }
967
+
957
968
#[ test]
958
969
fn pop_if_empty_in_bounds ( ) {
959
970
let mut url = Url :: parse ( "m://" ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments