@@ -158,3 +158,30 @@ assert.throws(() => params.set(`x${NOT_HTTP_TOKEN_CODE_POINT}`, 'x'), /parameter |
158 | 158 | assert.throws(() => params.set('x', `${NOT_HTTP_QUOTED_STRING_CODE_POINT};`), /parameter value/i); |
159 | 159 | assert.throws(() => params.set('x', `${NOT_HTTP_QUOTED_STRING_CODE_POINT}x`), /parameter value/i); |
160 | 160 | assert.throws(() => params.set('x', `x${NOT_HTTP_QUOTED_STRING_CODE_POINT}`), /parameter value/i); |
| 161 | + |
| 162 | +// MIME parameter names are case-insensitive. The parser lower-cases them, so |
| 163 | +// the MIMEParams accessors must lower-case their argument too; otherwise a |
| 164 | +// parsed parameter is unreachable by the casing the caller actually used and |
| 165 | +// `set()` can create case-colliding duplicate parameters. |
| 166 | +// Refs: https://mimesniff.spec.whatwg.org/ (parameter names are ASCII-lowercased) |
| 167 | +{ |
| 168 | + const mime = new MIMEType('text/plain;Charset=value'); |
| 169 | + assert.strictEqual(mime.params.get('Charset'), 'value'); |
| 170 | + assert.strictEqual(mime.params.get('charset'), 'value'); |
| 171 | + assert.strictEqual(mime.params.get('CHARSET'), 'value'); |
| 172 | + assert.strictEqual(mime.params.has('Charset'), true); |
| 173 | + assert.strictEqual(`${mime.params}`, 'charset=value'); |
| 174 | + |
| 175 | + // `set()` with a mixed-case name overwrites the same parameter rather than |
| 176 | + // adding a second, case-colliding one. |
| 177 | + const params = new MIMEType('text/plain').params; |
| 178 | + params.set('Foo', 'a'); |
| 179 | + params.set('foo', 'b'); |
| 180 | + assert.deepStrictEqual([...params], [['foo', 'b']]); |
| 181 | + assert.strictEqual(`${params}`, 'foo=b'); |
| 182 | + |
| 183 | + // `delete()` is case-insensitive as well. |
| 184 | + params.delete('FOO'); |
| 185 | + assert.strictEqual(params.has('foo'), false); |
| 186 | + assert.deepStrictEqual([...params], []); |
| 187 | +} |