{{ message }}
fix(utils.url): delete existing key before appending array values in withQuery#594
Open
LeSingh1 wants to merge 1 commit into
Open
fix(utils.url): delete existing key before appending array values in withQuery#594LeSingh1 wants to merge 1 commit into
LeSingh1 wants to merge 1 commit into
Conversation
…withQuery
When withQuery merges a query object into a URL that already has an
existing query string, scalar values are correctly replaced via
searchParams.set(). Array values, however, were appended without first
deleting the existing key for that name, so the old value would persist
alongside the new ones.
For example:
withQuery('https://example.org/path?tag=old', { tag: ['a', 'b'] })
produced: ...?tag=old&tag=a&tag=b (wrong)
now gives: ...?tag=a&tag=b (correct)
Add searchParams.delete(key) before the append loop to match the
replace semantics that searchParams.set() already provides for
scalar values.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/index.test.ts (1)
347-359: 💤 Low valueConsider asserting that non-replaced parameters are preserved.
The test verifies that
tag=oldis replaced bytag=aandtag=b, but doesn't explicitly check thatother=1(which isn't in the query object) remains in the result. While the PR description mentions this ("result: ?other=1&tag=a&tag=b"), adding an assertion likeexpect(result).toContain("other=1")would more thoroughly verify the replace-not-merge semantics.📋 Optional assertion to verify parameter preservation
expect(result).toContain("tag=a"); expect(result).toContain("tag=b"); expect(result).not.toContain("tag=old"); + expect(result).toContain("other=1"); });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/index.test.ts` around lines 347 - 359, The test "replaces existing array query params instead of accumulating" checks that tag=old is removed when passing query: { tag: ["a","b"] } but doesn't assert that unrelated existing params are preserved; update the test case (the it block titled "replaces existing array query params instead of accumulating") to add an expectation that the original other=1 remains (use the same result from await $fetch(getURL("url/check?tag=old&other=1"), { query: { tag: ["a","b"] } }) and add expect(result).toContain("other=1") so the test verifies replace-not-merge semantics while preserving unrelated query params).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@test/index.test.ts`:
- Around line 347-359: The test "replaces existing array query params instead of
accumulating" checks that tag=old is removed when passing query: { tag:
["a","b"] } but doesn't assert that unrelated existing params are preserved;
update the test case (the it block titled "replaces existing array query params
instead of accumulating") to add an expectation that the original other=1
remains (use the same result from await
$fetch(getURL("url/check?tag=old&other=1"), { query: { tag: ["a","b"] } }) and
add expect(result).toContain("other=1") so the test verifies replace-not-merge
semantics while preserving unrelated query params).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 57232bfe-5210-4dce-b7dc-f8bcd759ab44
📒 Files selected for processing (2)
src/utils.url.tstest/index.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

When
withQueryis called with a URL that already has a query string, scalar values are replaced correctly viasearchParams.set(). Array values, though, were only appended without first removing the old entries for that key, so the original value leaked into the final URL alongside the new ones.Example before this fix:
After:
The fix adds
searchParams.delete(key)before theappendloop, matching the replace semantics thatsearchParams.set()already provides for scalar values. A new test covers the case by fetching through the real h3 server and asserting the raw path+search echoed back.All 29 tests pass.
Summary by CodeRabbit
Bug Fixes
Tests