Skip to content
Myr

fix(accept): treat the q parameter name as case-insensitive (#5349)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Mochammad Fadhlan Al-Ghiffari · committed by GitHub · parent f147de5 · Browse files · 2 files+16 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+16 added−1 removed

  • tests:+13 added−0 removed
  • other:+3 added−1 removed

2 files+16 added−1 removed

modified:src/utils/accept.test.ts+13 added
41 unmodified lines
42 const result = parseAccept(header)43 expect(result[0].params.q).toBe('invalid')44 expect(result[0].q).toBe(1) // Normalized q value45 })4647 test('treats the q parameter name as case-insensitive', () => {48 // RFC 9110 §12.4.2: the "q" parameter is case-insensitive.49 expect(parseAccept('text/html;Q=0.5')).toEqual([50 { type: 'text/html', params: { Q: '0.5' }, q: 0.5 },51 ])52 expect(parseAccept('text/html;Q=0')[0].q).toBe(0)53 })5455 test('sorts by quality when the q parameter is uppercase', () => {56 const result = parseAccept('text/html;Q=0.5,application/json;q=0.9')57 expect(result.map((x) => x.type)).toEqual(['application/json', 'text/html'])58 })59 })6061 describe('Parameter Handling', () => {62 test('handles complex parameters', () => {
218 unmodified lines
modified:src/utils/accept.ts+3 added-1 removed
219 unmodified lines
220 let lastAccept: Accept | undefined221 while (i < acceptHeader.length) {222 ;[i, accept] = getNextAcceptValue(acceptHeader, i)223 if (accept) {224 // The "q" parameter is case-insensitive (RFC 9110 §12.4.2). `params` keeps225 // the name as it was sent, so both spellings are checked here.224 accept.q = parseQuality(accept.params.q)226 accept.q = parseQuality(accept.params.q ?? accept.params.Q)227 values.push(accept)228 if (lastAccept && lastAccept.q < accept.q) {229 // find higher quality accept value, so we need to sort230 requiresSort = true
38 unmodified lines