fix: allow passing array to query parameters#253
Conversation
WalkthroughQuery-string serialization in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/treaty2/index.ts (1)
280-286:⚠️ Potential issue | 🔴 CriticalAvoid appending array query parameters twice.
Line 285 executes even when
valueis an array, so the request includes bothkey[]=...entries and a secondkey=<json-array>entry. This can break query validation and conflicts with the intended array format.Proposed fix
for (const [key, value] of Object.entries(query)) { if (Array.isArray(value)) { for (const v of value) append(key, v, true) + continue } append(key, value) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/treaty2/index.ts` around lines 280 - 286, The loop over Object.entries(query) appends array values twice because after handling Array.isArray(value) with append(key, v, true) it still falls through to append(key, value); modify the loop in src/treaty2/index.ts so that when Array.isArray(value) is true you do not call append(key, value) (use an else or continue) — keep using append(key, v, true) for each element of the array and only call append(key, value) for non-array values.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/treaty2/index.ts`:
- Around line 280-286: The loop over Object.entries(query) appends array values
twice because after handling Array.isArray(value) with append(key, v, true) it
still falls through to append(key, value); modify the loop in
src/treaty2/index.ts so that when Array.isArray(value) is true you do not call
append(key, value) (use an else or continue) — keep using append(key, v, true)
for each element of the array and only call append(key, value) for non-array
values.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 85b84852-5617-44b6-83de-38af622275ff
📒 Files selected for processing (1)
src/treaty2/index.ts
The validation fail on server if it expect array in query string
Summary by CodeRabbit