11cb0ef41Sopenharmony_citest(function() { 21cb0ef41Sopenharmony_ci var params = new URLSearchParams(); 31cb0ef41Sopenharmony_ci params.append('a', 'b c'); 41cb0ef41Sopenharmony_ci assert_equals(params + '', 'a=b+c'); 51cb0ef41Sopenharmony_ci params.delete('a'); 61cb0ef41Sopenharmony_ci params.append('a b', 'c'); 71cb0ef41Sopenharmony_ci assert_equals(params + '', 'a+b=c'); 81cb0ef41Sopenharmony_ci}, 'Serialize space'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_citest(function() { 111cb0ef41Sopenharmony_ci var params = new URLSearchParams(); 121cb0ef41Sopenharmony_ci params.append('a', ''); 131cb0ef41Sopenharmony_ci assert_equals(params + '', 'a='); 141cb0ef41Sopenharmony_ci params.append('a', ''); 151cb0ef41Sopenharmony_ci assert_equals(params + '', 'a=&a='); 161cb0ef41Sopenharmony_ci params.append('', 'b'); 171cb0ef41Sopenharmony_ci assert_equals(params + '', 'a=&a=&=b'); 181cb0ef41Sopenharmony_ci params.append('', ''); 191cb0ef41Sopenharmony_ci assert_equals(params + '', 'a=&a=&=b&='); 201cb0ef41Sopenharmony_ci params.append('', ''); 211cb0ef41Sopenharmony_ci assert_equals(params + '', 'a=&a=&=b&=&='); 221cb0ef41Sopenharmony_ci}, 'Serialize empty value'); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_citest(function() { 251cb0ef41Sopenharmony_ci var params = new URLSearchParams(); 261cb0ef41Sopenharmony_ci params.append('', 'b'); 271cb0ef41Sopenharmony_ci assert_equals(params + '', '=b'); 281cb0ef41Sopenharmony_ci params.append('', 'b'); 291cb0ef41Sopenharmony_ci assert_equals(params + '', '=b&=b'); 301cb0ef41Sopenharmony_ci}, 'Serialize empty name'); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_citest(function() { 331cb0ef41Sopenharmony_ci var params = new URLSearchParams(); 341cb0ef41Sopenharmony_ci params.append('', ''); 351cb0ef41Sopenharmony_ci assert_equals(params + '', '='); 361cb0ef41Sopenharmony_ci params.append('', ''); 371cb0ef41Sopenharmony_ci assert_equals(params + '', '=&='); 381cb0ef41Sopenharmony_ci}, 'Serialize empty name and value'); 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_citest(function() { 411cb0ef41Sopenharmony_ci var params = new URLSearchParams(); 421cb0ef41Sopenharmony_ci params.append('a', 'b+c'); 431cb0ef41Sopenharmony_ci assert_equals(params + '', 'a=b%2Bc'); 441cb0ef41Sopenharmony_ci params.delete('a'); 451cb0ef41Sopenharmony_ci params.append('a+b', 'c'); 461cb0ef41Sopenharmony_ci assert_equals(params + '', 'a%2Bb=c'); 471cb0ef41Sopenharmony_ci}, 'Serialize +'); 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_citest(function() { 501cb0ef41Sopenharmony_ci var params = new URLSearchParams(); 511cb0ef41Sopenharmony_ci params.append('=', 'a'); 521cb0ef41Sopenharmony_ci assert_equals(params + '', '%3D=a'); 531cb0ef41Sopenharmony_ci params.append('b', '='); 541cb0ef41Sopenharmony_ci assert_equals(params + '', '%3D=a&b=%3D'); 551cb0ef41Sopenharmony_ci}, 'Serialize ='); 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_citest(function() { 581cb0ef41Sopenharmony_ci var params = new URLSearchParams(); 591cb0ef41Sopenharmony_ci params.append('&', 'a'); 601cb0ef41Sopenharmony_ci assert_equals(params + '', '%26=a'); 611cb0ef41Sopenharmony_ci params.append('b', '&'); 621cb0ef41Sopenharmony_ci assert_equals(params + '', '%26=a&b=%26'); 631cb0ef41Sopenharmony_ci}, 'Serialize &'); 641cb0ef41Sopenharmony_ci 651cb0ef41Sopenharmony_citest(function() { 661cb0ef41Sopenharmony_ci var params = new URLSearchParams(); 671cb0ef41Sopenharmony_ci params.append('a', '*-._'); 681cb0ef41Sopenharmony_ci assert_equals(params + '', 'a=*-._'); 691cb0ef41Sopenharmony_ci params.delete('a'); 701cb0ef41Sopenharmony_ci params.append('*-._', 'c'); 711cb0ef41Sopenharmony_ci assert_equals(params + '', '*-._=c'); 721cb0ef41Sopenharmony_ci}, 'Serialize *-._'); 731cb0ef41Sopenharmony_ci 741cb0ef41Sopenharmony_citest(function() { 751cb0ef41Sopenharmony_ci var params = new URLSearchParams(); 761cb0ef41Sopenharmony_ci params.append('a', 'b%c'); 771cb0ef41Sopenharmony_ci assert_equals(params + '', 'a=b%25c'); 781cb0ef41Sopenharmony_ci params.delete('a'); 791cb0ef41Sopenharmony_ci params.append('a%b', 'c'); 801cb0ef41Sopenharmony_ci assert_equals(params + '', 'a%25b=c'); 811cb0ef41Sopenharmony_ci 821cb0ef41Sopenharmony_ci params = new URLSearchParams('id=0&value=%') 831cb0ef41Sopenharmony_ci assert_equals(params + '', 'id=0&value=%25') 841cb0ef41Sopenharmony_ci}, 'Serialize %'); 851cb0ef41Sopenharmony_ci 861cb0ef41Sopenharmony_citest(function() { 871cb0ef41Sopenharmony_ci var params = new URLSearchParams(); 881cb0ef41Sopenharmony_ci params.append('a', 'b\0c'); 891cb0ef41Sopenharmony_ci assert_equals(params + '', 'a=b%00c'); 901cb0ef41Sopenharmony_ci params.delete('a'); 911cb0ef41Sopenharmony_ci params.append('a\0b', 'c'); 921cb0ef41Sopenharmony_ci assert_equals(params + '', 'a%00b=c'); 931cb0ef41Sopenharmony_ci}, 'Serialize \\0'); 941cb0ef41Sopenharmony_ci 951cb0ef41Sopenharmony_citest(function() { 961cb0ef41Sopenharmony_ci var params = new URLSearchParams(); 971cb0ef41Sopenharmony_ci params.append('a', 'b\uD83D\uDCA9c'); 981cb0ef41Sopenharmony_ci assert_equals(params + '', 'a=b%F0%9F%92%A9c'); 991cb0ef41Sopenharmony_ci params.delete('a'); 1001cb0ef41Sopenharmony_ci params.append('a\uD83D\uDCA9b', 'c'); 1011cb0ef41Sopenharmony_ci assert_equals(params + '', 'a%F0%9F%92%A9b=c'); 1021cb0ef41Sopenharmony_ci}, 'Serialize \uD83D\uDCA9'); // Unicode Character 'PILE OF POO' (U+1F4A9) 1031cb0ef41Sopenharmony_ci 1041cb0ef41Sopenharmony_citest(function() { 1051cb0ef41Sopenharmony_ci var params; 1061cb0ef41Sopenharmony_ci params = new URLSearchParams('a=b&c=d&&e&&'); 1071cb0ef41Sopenharmony_ci assert_equals(params.toString(), 'a=b&c=d&e='); 1081cb0ef41Sopenharmony_ci params = new URLSearchParams('a = b &a=b&c=d%20'); 1091cb0ef41Sopenharmony_ci assert_equals(params.toString(), 'a+=+b+&a=b&c=d+'); 1101cb0ef41Sopenharmony_ci // The lone '=' _does_ survive the roundtrip. 1111cb0ef41Sopenharmony_ci params = new URLSearchParams('a=&a=b'); 1121cb0ef41Sopenharmony_ci assert_equals(params.toString(), 'a=&a=b'); 1131cb0ef41Sopenharmony_ci 1141cb0ef41Sopenharmony_ci params = new URLSearchParams('b=%2sf%2a'); 1151cb0ef41Sopenharmony_ci assert_equals(params.toString(), 'b=%252sf*'); 1161cb0ef41Sopenharmony_ci 1171cb0ef41Sopenharmony_ci params = new URLSearchParams('b=%2%2af%2a'); 1181cb0ef41Sopenharmony_ci assert_equals(params.toString(), 'b=%252*f*'); 1191cb0ef41Sopenharmony_ci 1201cb0ef41Sopenharmony_ci params = new URLSearchParams('b=%%2a'); 1211cb0ef41Sopenharmony_ci assert_equals(params.toString(), 'b=%25*'); 1221cb0ef41Sopenharmony_ci}, 'URLSearchParams.toString'); 1231cb0ef41Sopenharmony_ci 1241cb0ef41Sopenharmony_citest(() => { 1251cb0ef41Sopenharmony_ci const url = new URL('http://www.example.com/?a=b,c'); 1261cb0ef41Sopenharmony_ci const params = url.searchParams; 1271cb0ef41Sopenharmony_ci 1281cb0ef41Sopenharmony_ci assert_equals(url.toString(), 'http://www.example.com/?a=b,c'); 1291cb0ef41Sopenharmony_ci assert_equals(params.toString(), 'a=b%2Cc'); 1301cb0ef41Sopenharmony_ci 1311cb0ef41Sopenharmony_ci params.append('x', 'y'); 1321cb0ef41Sopenharmony_ci 1331cb0ef41Sopenharmony_ci assert_equals(url.toString(), 'http://www.example.com/?a=b%2Cc&x=y'); 1341cb0ef41Sopenharmony_ci assert_equals(params.toString(), 'a=b%2Cc&x=y'); 1351cb0ef41Sopenharmony_ci}, 'URLSearchParams connected to URL'); 1361cb0ef41Sopenharmony_ci 1371cb0ef41Sopenharmony_citest(() => { 1381cb0ef41Sopenharmony_ci const url = new URL('http://www.example.com/'); 1391cb0ef41Sopenharmony_ci const params = url.searchParams; 1401cb0ef41Sopenharmony_ci 1411cb0ef41Sopenharmony_ci params.append('a\nb', 'c\rd'); 1421cb0ef41Sopenharmony_ci params.append('e\n\rf', 'g\r\nh'); 1431cb0ef41Sopenharmony_ci 1441cb0ef41Sopenharmony_ci assert_equals(params.toString(), "a%0Ab=c%0Dd&e%0A%0Df=g%0D%0Ah"); 1451cb0ef41Sopenharmony_ci}, 'URLSearchParams must not do newline normalization'); 146