OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <link rel="help" href="http://url.spec.whatwg.org/#interface-urlsearchparams-str
ingifier"> |
| 3 <script src="../../resources/testharness.js"></script> |
| 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 <script> |
| 6 test(function() { |
| 7 var params = new URLSearchParams(); |
| 8 params.append("a", "b c"); |
| 9 assert_equals(params + "", "a=b+c"); |
| 10 params.delete("a"); |
| 11 params.append("a b", "c"); |
| 12 assert_equals(params + "", "a+b=c"); |
| 13 }, "Serialize space"); |
| 14 |
| 15 test(function() { |
| 16 var params = new URLSearchParams(); |
| 17 params.append("a", ""); |
| 18 assert_equals(params + "", "a="); |
| 19 params.append("a", ""); |
| 20 assert_equals(params + "", "a=&a="); |
| 21 params.append("", "b"); |
| 22 assert_equals(params + "", "a=&a=&=b"); |
| 23 params.append("", ""); |
| 24 assert_equals(params + "", "a=&a=&=b&="); |
| 25 params.append("", ""); |
| 26 assert_equals(params + "", "a=&a=&=b&=&="); |
| 27 }, "Serialize empty value"); |
| 28 |
| 29 test(function() { |
| 30 var params = new URLSearchParams(); |
| 31 params.append("", "b"); |
| 32 assert_equals(params + "", "=b"); |
| 33 params.append("", "b"); |
| 34 assert_equals(params + "", "=b&=b"); |
| 35 }, "Serialize empty name"); |
| 36 |
| 37 test(function() { |
| 38 var params = new URLSearchParams(); |
| 39 params.append("", ""); |
| 40 assert_equals(params + "", "="); |
| 41 params.append("", ""); |
| 42 assert_equals(params + "", "=&="); |
| 43 }, "Serialize empty name and value"); |
| 44 |
| 45 test(function() { |
| 46 var params = new URLSearchParams(); |
| 47 params.append("a", "b+c"); |
| 48 assert_equals(params + "", "a=b%2Bc"); |
| 49 params.delete("a"); |
| 50 params.append("a+b", "c"); |
| 51 assert_equals(params + "", "a%2Bb=c"); |
| 52 }, "Serialize +"); |
| 53 |
| 54 test(function() { |
| 55 var params = new URLSearchParams(); |
| 56 params.append("=", "a"); |
| 57 assert_equals(params + "", "%3D=a"); |
| 58 params.append("b", "="); |
| 59 assert_equals(params + "", "%3D=a&b=%3D"); |
| 60 }, "Serialize ="); |
| 61 |
| 62 test(function() { |
| 63 var params = new URLSearchParams(); |
| 64 params.append("&", "a"); |
| 65 assert_equals(params + "", "%26=a"); |
| 66 params.append("b", "&"); |
| 67 assert_equals(params + "", "%26=a&b=%26"); |
| 68 }, "Serialize &"); |
| 69 |
| 70 test(function() { |
| 71 var params = new URLSearchParams(); |
| 72 params.append("a", "*-._"); |
| 73 assert_equals(params + "", "a=*-._"); |
| 74 params.delete("a"); |
| 75 params.append("*-._", "c"); |
| 76 assert_equals(params + "", "*-._=c"); |
| 77 }, "Serialize *-._"); |
| 78 |
| 79 test(function() { |
| 80 var params = new URLSearchParams(); |
| 81 params.append("a", "b%c"); |
| 82 assert_equals(params + "", "a=b%25c"); |
| 83 params.delete("a"); |
| 84 params.append("a%b", "c"); |
| 85 assert_equals(params + "", "a%25b=c"); |
| 86 }, "Serialize %"); |
| 87 |
| 88 test(function() { |
| 89 var params = new URLSearchParams(); |
| 90 params.append("a", "b\0c"); |
| 91 assert_equals(params + "", "a=b%00c"); |
| 92 params.delete("a"); |
| 93 params.append("a\0b", "c"); |
| 94 assert_equals(params + "", "a%00b=c"); |
| 95 }, "Serialize \\0"); |
| 96 |
| 97 test(function() { |
| 98 var params = new URLSearchParams(); |
| 99 params.append("a", "b\uD83D\uDCA9c"); |
| 100 assert_equals(params + "", "a=b%F0%9F%92%A9c"); |
| 101 params.delete("a"); |
| 102 params.append("a\uD83D\uDCA9b", "c"); |
| 103 assert_equals(params + "", "a%F0%9F%92%A9b=c"); |
| 104 }, "Serialize \uD83D\uDCA9"); // Unicode Character "PILE OF POO" (U+1F4A9) |
| 105 |
| 106 test(function() { |
| 107 var params; |
| 108 params = new URLSearchParams("a=b&c=d&&e&&"); |
| 109 assert_equals(params.toString(), "a=b&c=d&e="); |
| 110 |
| 111 params = new URLSearchParams("a = b &a=b&c=d%20"); |
| 112 assert_equals(params.toString(), "a+=+b+&a=b&c=d+"); |
| 113 |
| 114 // The lone "=" _does_ survive the roundtrip. |
| 115 params = new URLSearchParams("a=&a=b"); |
| 116 assert_equals(params.toString(), "a=&a=b"); |
| 117 }, "URLSearchParams.toString"); |
| 118 </script> |
OLD | NEW |