Commit 53d6fae
committed
fix(api): handle whitespace around q-parameter in Accept negotiation
Round 2 review (#82): CodeRabbit flagged that the round-1 q parsing
used `param.startsWith("q=")` which only matches the compact form.
Per RFC 7230 §3.2.6, optional whitespace is permitted around the `=`
in `parameter = token "=" ( token / quoted-string )`, so a strict
client may send `Accept: text/event-stream ; q = 0`. The prior fix
treated such forms as "no q parameter present" and returned true,
incorrectly opting the client into streaming.
Replaced startsWith check with an indexOf("=") + slice + trim pass:
parse name and value separately so whitespace around the delimiter
no longer hides q. Empty `q=` value now correctly resolves to false
(Number("") = 0, fails q > 0).
Verified before/after:
- text/event-stream ; q = 0 → was true, now false
- text/event-stream ; q = 0.5 → was true (default-q path), now true (real q parsed)
- text/event-stream;q=0 → still false (round-1 case)
- text/event-stream;q= → was true (empty slice), now false
Tests: api-helpers.test.ts +3 cases covering whitespace q=0,
whitespace q=0.5, and empty q value. 12 → 15 cases.1 parent f30fe7a commit 53d6fae
2 files changed
Lines changed: 25 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
49 | 61 | | |
50 | 62 | | |
51 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
68 | | - | |
69 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
70 | 79 | | |
71 | | - | |
72 | | - | |
| 80 | + | |
73 | 81 | | |
74 | 82 | | |
75 | 83 | | |
| |||
0 commit comments