cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
tests/qs/empty-keys-cases.ts
271lines · modecode
| 1 | export const empty_test_cases = [ |
| 2 | { |
| 3 | input: '&', |
| 4 | with_empty_keys: {}, |
| 5 | stringify_output: { |
| 6 | brackets: '', |
| 7 | indices: '', |
| 8 | repeat: '', |
| 9 | }, |
| 10 | no_empty_keys: {}, |
| 11 | }, |
| 12 | { |
| 13 | input: '&&', |
| 14 | with_empty_keys: {}, |
| 15 | stringify_output: { |
| 16 | brackets: '', |
| 17 | indices: '', |
| 18 | repeat: '', |
| 19 | }, |
| 20 | no_empty_keys: {}, |
| 21 | }, |
| 22 | { |
| 23 | input: '&=', |
| 24 | with_empty_keys: { '': '' }, |
| 25 | stringify_output: { |
| 26 | brackets: '=', |
| 27 | indices: '=', |
| 28 | repeat: '=', |
| 29 | }, |
| 30 | no_empty_keys: {}, |
| 31 | }, |
| 32 | { |
| 33 | input: '&=&', |
| 34 | with_empty_keys: { '': '' }, |
| 35 | stringify_output: { |
| 36 | brackets: '=', |
| 37 | indices: '=', |
| 38 | repeat: '=', |
| 39 | }, |
| 40 | no_empty_keys: {}, |
| 41 | }, |
| 42 | { |
| 43 | input: '&=&=', |
| 44 | with_empty_keys: { '': ['', ''] }, |
| 45 | stringify_output: { |
| 46 | brackets: '[]=&[]=', |
| 47 | indices: '[0]=&[1]=', |
| 48 | repeat: '=&=', |
| 49 | }, |
| 50 | no_empty_keys: {}, |
| 51 | }, |
| 52 | { |
| 53 | input: '&=&=&', |
| 54 | with_empty_keys: { '': ['', ''] }, |
| 55 | stringify_output: { |
| 56 | brackets: '[]=&[]=', |
| 57 | indices: '[0]=&[1]=', |
| 58 | repeat: '=&=', |
| 59 | }, |
| 60 | no_empty_keys: {}, |
| 61 | }, |
| 62 | { |
| 63 | input: '=', |
| 64 | with_empty_keys: { '': '' }, |
| 65 | no_empty_keys: {}, |
| 66 | stringify_output: { |
| 67 | brackets: '=', |
| 68 | indices: '=', |
| 69 | repeat: '=', |
| 70 | }, |
| 71 | }, |
| 72 | { |
| 73 | input: '=&', |
| 74 | with_empty_keys: { '': '' }, |
| 75 | stringify_output: { |
| 76 | brackets: '=', |
| 77 | indices: '=', |
| 78 | repeat: '=', |
| 79 | }, |
| 80 | no_empty_keys: {}, |
| 81 | }, |
| 82 | { |
| 83 | input: '=&&&', |
| 84 | with_empty_keys: { '': '' }, |
| 85 | stringify_output: { |
| 86 | brackets: '=', |
| 87 | indices: '=', |
| 88 | repeat: '=', |
| 89 | }, |
| 90 | no_empty_keys: {}, |
| 91 | }, |
| 92 | { |
| 93 | input: '=&=&=&', |
| 94 | with_empty_keys: { '': ['', '', ''] }, |
| 95 | stringify_output: { |
| 96 | brackets: '[]=&[]=&[]=', |
| 97 | indices: '[0]=&[1]=&[2]=', |
| 98 | repeat: '=&=&=', |
| 99 | }, |
| 100 | no_empty_keys: {}, |
| 101 | }, |
| 102 | { |
| 103 | input: '=&a[]=b&a[1]=c', |
| 104 | with_empty_keys: { '': '', a: ['b', 'c'] }, |
| 105 | stringify_output: { |
| 106 | brackets: '=&a[]=b&a[]=c', |
| 107 | indices: '=&a[0]=b&a[1]=c', |
| 108 | repeat: '=&a=b&a=c', |
| 109 | }, |
| 110 | no_empty_keys: { a: ['b', 'c'] }, |
| 111 | }, |
| 112 | { |
| 113 | input: '=a', |
| 114 | with_empty_keys: { '': 'a' }, |
| 115 | no_empty_keys: {}, |
| 116 | stringify_output: { |
| 117 | brackets: '=a', |
| 118 | indices: '=a', |
| 119 | repeat: '=a', |
| 120 | }, |
| 121 | }, |
| 122 | { |
| 123 | input: 'a==a', |
| 124 | with_empty_keys: { a: '=a' }, |
| 125 | no_empty_keys: { a: '=a' }, |
| 126 | stringify_output: { |
| 127 | brackets: 'a==a', |
| 128 | indices: 'a==a', |
| 129 | repeat: 'a==a', |
| 130 | }, |
| 131 | }, |
| 132 | { |
| 133 | input: '=&a[]=b', |
| 134 | with_empty_keys: { '': '', a: ['b'] }, |
| 135 | stringify_output: { |
| 136 | brackets: '=&a[]=b', |
| 137 | indices: '=&a[0]=b', |
| 138 | repeat: '=&a=b', |
| 139 | }, |
| 140 | no_empty_keys: { a: ['b'] }, |
| 141 | }, |
| 142 | { |
| 143 | input: '=&a[]=b&a[]=c&a[2]=d', |
| 144 | with_empty_keys: { '': '', a: ['b', 'c', 'd'] }, |
| 145 | stringify_output: { |
| 146 | brackets: '=&a[]=b&a[]=c&a[]=d', |
| 147 | indices: '=&a[0]=b&a[1]=c&a[2]=d', |
| 148 | repeat: '=&a=b&a=c&a=d', |
| 149 | }, |
| 150 | no_empty_keys: { a: ['b', 'c', 'd'] }, |
| 151 | }, |
| 152 | { |
| 153 | input: '=a&=b', |
| 154 | with_empty_keys: { '': ['a', 'b'] }, |
| 155 | stringify_output: { |
| 156 | brackets: '[]=a&[]=b', |
| 157 | indices: '[0]=a&[1]=b', |
| 158 | repeat: '=a&=b', |
| 159 | }, |
| 160 | no_empty_keys: {}, |
| 161 | }, |
| 162 | { |
| 163 | input: '=a&foo=b', |
| 164 | with_empty_keys: { '': 'a', foo: 'b' }, |
| 165 | no_empty_keys: { foo: 'b' }, |
| 166 | stringify_output: { |
| 167 | brackets: '=a&foo=b', |
| 168 | indices: '=a&foo=b', |
| 169 | repeat: '=a&foo=b', |
| 170 | }, |
| 171 | }, |
| 172 | { |
| 173 | input: 'a[]=b&a=c&=', |
| 174 | with_empty_keys: { '': '', a: ['b', 'c'] }, |
| 175 | stringify_output: { |
| 176 | brackets: '=&a[]=b&a[]=c', |
| 177 | indices: '=&a[0]=b&a[1]=c', |
| 178 | repeat: '=&a=b&a=c', |
| 179 | }, |
| 180 | no_empty_keys: { a: ['b', 'c'] }, |
| 181 | }, |
| 182 | { |
| 183 | input: 'a[]=b&a=c&=', |
| 184 | with_empty_keys: { '': '', a: ['b', 'c'] }, |
| 185 | stringify_output: { |
| 186 | brackets: '=&a[]=b&a[]=c', |
| 187 | indices: '=&a[0]=b&a[1]=c', |
| 188 | repeat: '=&a=b&a=c', |
| 189 | }, |
| 190 | no_empty_keys: { a: ['b', 'c'] }, |
| 191 | }, |
| 192 | { |
| 193 | input: 'a[0]=b&a=c&=', |
| 194 | with_empty_keys: { '': '', a: ['b', 'c'] }, |
| 195 | stringify_output: { |
| 196 | brackets: '=&a[]=b&a[]=c', |
| 197 | indices: '=&a[0]=b&a[1]=c', |
| 198 | repeat: '=&a=b&a=c', |
| 199 | }, |
| 200 | no_empty_keys: { a: ['b', 'c'] }, |
| 201 | }, |
| 202 | { |
| 203 | input: 'a=b&a[]=c&=', |
| 204 | with_empty_keys: { '': '', a: ['b', 'c'] }, |
| 205 | stringify_output: { |
| 206 | brackets: '=&a[]=b&a[]=c', |
| 207 | indices: '=&a[0]=b&a[1]=c', |
| 208 | repeat: '=&a=b&a=c', |
| 209 | }, |
| 210 | no_empty_keys: { a: ['b', 'c'] }, |
| 211 | }, |
| 212 | { |
| 213 | input: 'a=b&a[0]=c&=', |
| 214 | with_empty_keys: { '': '', a: ['b', 'c'] }, |
| 215 | stringify_output: { |
| 216 | brackets: '=&a[]=b&a[]=c', |
| 217 | indices: '=&a[0]=b&a[1]=c', |
| 218 | repeat: '=&a=b&a=c', |
| 219 | }, |
| 220 | no_empty_keys: { a: ['b', 'c'] }, |
| 221 | }, |
| 222 | { |
| 223 | input: '[]=a&[]=b& []=1', |
| 224 | with_empty_keys: { '': ['a', 'b'], ' ': ['1'] }, |
| 225 | stringify_output: { |
| 226 | brackets: '[]=a&[]=b& []=1', |
| 227 | indices: '[0]=a&[1]=b& [0]=1', |
| 228 | repeat: '=a&=b& =1', |
| 229 | }, |
| 230 | no_empty_keys: { 0: 'a', 1: 'b', ' ': ['1'] }, |
| 231 | }, |
| 232 | { |
| 233 | input: '[0]=a&[1]=b&a[0]=1&a[1]=2', |
| 234 | with_empty_keys: { '': ['a', 'b'], a: ['1', '2'] }, |
| 235 | no_empty_keys: { 0: 'a', 1: 'b', a: ['1', '2'] }, |
| 236 | stringify_output: { |
| 237 | brackets: '[]=a&[]=b&a[]=1&a[]=2', |
| 238 | indices: '[0]=a&[1]=b&a[0]=1&a[1]=2', |
| 239 | repeat: '=a&=b&a=1&a=2', |
| 240 | }, |
| 241 | }, |
| 242 | { |
| 243 | input: '[deep]=a&[deep]=2', |
| 244 | with_empty_keys: { '': { deep: ['a', '2'] } }, |
| 245 | stringify_output: { |
| 246 | brackets: '[deep][]=a&[deep][]=2', |
| 247 | indices: '[deep][0]=a&[deep][1]=2', |
| 248 | repeat: '[deep]=a&[deep]=2', |
| 249 | }, |
| 250 | no_empty_keys: { deep: ['a', '2'] }, |
| 251 | }, |
| 252 | { |
| 253 | input: '%5B0%5D=a&%5B1%5D=b', |
| 254 | with_empty_keys: { '': ['a', 'b'] }, |
| 255 | stringify_output: { |
| 256 | brackets: '[]=a&[]=b', |
| 257 | indices: '[0]=a&[1]=b', |
| 258 | repeat: '=a&=b', |
| 259 | }, |
| 260 | no_empty_keys: { 0: 'a', 1: 'b' }, |
| 261 | }, |
| 262 | ] satisfies { |
| 263 | input: string; |
| 264 | with_empty_keys: Record<string, unknown>; |
| 265 | stringify_output: { |
| 266 | brackets: string; |
| 267 | indices: string; |
| 268 | repeat: string; |
| 269 | }; |
| 270 | no_empty_keys: Record<string, unknown>; |
| 271 | }[]; |
| 272 | |