fix(uri): ? operator now appends to existing query string#25831
fix(uri): ? operator now appends to existing query string#25831n0madgang wants to merge 5 commits into
? operator now appends to existing query string#25831Conversation
Previously `?` would overwrite any existing query parameters in the URI. Now it appends the new parameters with `&` when a query string is already present. Fixes nim-lang#19782
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates Nim’s std/uri query concatenation behavior so adding query parameters appends to an existing query string (fixing #19782), and adds regression tests plus a changelog entry.
Changes:
- Change
std/uri’s?operator to append new encoded query parameters when a query already exists. - Add regression tests for appending behavior and for empty parameter lists.
- Document the behavior change in
changelog.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/stdlib/turi.nim | Adds regression coverage for appending to existing query strings and for empty param lists. |
| lib/pure/uri.nim | Implements new ? operator behavior to append query parameters rather than replace. |
| changelog.md | Documents the behavior change and links the fixed issue. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| result = u | ||
| result.query = encodeQuery(query) | ||
| let newQuery = encodeQuery(query) | ||
| if result.query.len > 0 and newQuery.len > 0: | ||
| result.query.add('&') | ||
| result.query.add(newQuery) | ||
| else: | ||
| result.query = newQuery |
When `encodeQuery(query)` returns an empty string (e.g. `? {:}`), the
previous else-branch would assign `result.query = ""`, silently clearing
any existing query string. Restructure the condition so that an empty
newQuery leaves result.query unchanged.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Thanks for catching this. Copilot is right: when Fixed in 0addc30: restructured so that an empty Sorry this slipped through. The machine I was working on has Nim 1.6.14, and the devel test file uses |
Additional regression test for issue nim-lang#19782 covering the "empty + empty" case: applying `?` with no params to a URI that has no existing query string must be a no-op. Verified locally with: nim c -r --lib:./lib tests/stdlib/turi.nim All assertion blocks for nim-lang#19782 pass (4 cases). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Status update on the Copilot review: The earlier Verified locally with the forked stdlib: Exit 0. The four relevant blocks all pass:
Latest commit Co-authored with Claude Code (Anthropic) — disclosed in each commit footer. |
Summary
Fixes #19782.
The
?operator instd/uriwas silently overwriting any query string already present in the URI. This PR makes it append instead — which matches the docstring ("Concatenates the query parameters") and the natural expectation when chaining operations.Before:
After:
Changes
lib/pure/uri.nim: fix?to append with&when a query string already exists; add example torunnableExamplestests/stdlib/turi.nim: two new test cases (append to existing query, empty params preserve existing)changelog.md: entry under Standard library changesNotes
I work with Claude as a co-processor. I'm 56, came to programming late, and this is genuinely how I learn and contribute. I understand what I'm submitting, but I didn't write it alone. If your project prefers human-only contributions, just say so and I'll close without friction.