Skip to content

fix: allow passing array to query parameters#253

Open
abihf wants to merge 3 commits into
elysiajs:mainfrom
abihf:patch-1
Open

fix: allow passing array to query parameters#253
abihf wants to merge 3 commits into
elysiajs:mainfrom
abihf:patch-1

Conversation

@abihf
Copy link
Copy Markdown

@abihf abihf commented Mar 19, 2026

The validation fail on server if it expect array in query string

Summary by CodeRabbit

  • Bug Fixes
    • Fixed query-string serialization for array values in GET/HEAD/subscribe requests so array items are encoded using bracketed keys (e.g., key[]). This ensures multi-value query parameters are formatted consistently and prevents malformed or ambiguous query strings when sending array data.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 19, 2026

Walkthrough

Query-string serialization in createProxy (GET/HEAD/subscribe) was changed: the append helper now accepts an isArray flag and array values are serialized as key[] by calling append(key, value, true). Loop flow was adjusted to explicitly continue after handling array entries.

Changes

Cohort / File(s) Summary
Query-string Array Serialization
src/treaty2/index.ts
append helper gains an isArray boolean to serialize array entries as key[]. Iteration over query entries now calls append(key, v, true) for array elements and explicitly continues after handling arrays; minor control-flow/whitespace adjustments.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I nibble keys and add a pair of braces,
Now every hop gives key[] embraces.
Loops made tidy, params parade,
A rabbit's patch of cleaner code displayed. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title 'fix: allow passing array to query parameters' directly and accurately reflects the main change: enabling array parameters in query strings with proper serialization using the key[] format.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🔴 Critical

Avoid appending array query parameters twice.

Line 285 executes even when value is an array, so the request includes both key[]=... entries and a second key=<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

📥 Commits

Reviewing files that changed from the base of the PR and between f92338c and 6d8c435.

📒 Files selected for processing (1)
  • src/treaty2/index.ts

@abihf abihf changed the title feat: allow passing array to query parameters fix: allow passing array to query parameters Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant