Skip to content

assert: preserve URL queries when HTTP status parameters are empty - #2001

Open
JunaidAhamed-7777 wants to merge 1 commit into
stretchr:masterfrom
JunaidAhamed-7777:fix/http-status-preserve-url-query
Open

JunaidAhamed-7777 wants to merge 1 commit into
stretchr:masterfrom
JunaidAhamed-7777:fix/http-status-preserve-url-query

Conversation

@JunaidAhamed-7777

@JunaidAhamed-7777 JunaidAhamed-7777 commented Oct 31, 2026 •

Copy link
Copy Markdown

Summary

Preserve queries already present in the target URL when HTTP status assertions receive nil or empty url.Values.

Changes

  • Only replace req.URL.RawQuery when the separate values map is nonempty.
  • Preserve existing replacement—not merging—semantics for nonempty maps, including url.Values{"q": nil}, which encodes to an empty string and clears the query.
  • Add helper regressions for nil/empty values, escaping, repeated keys, fragments, absent queries, and explicit replacement, plus a public HTTPStatusCode regression.

Motivation

A handler requiring q=hello world currently receives no query from:

assert.HTTPStatusCode(t, handler, "GET", "/search?q=hello%20world", nil, http.StatusOK)

That can make an assertion exercise a different request than its caller supplied. This intentionally corrects nil/empty-parameter behavior; exported signatures remain unchanged. It aligns this case with HTTPBody, but does not modify HTTPBody or introduce query merging.

Related issues

No matching open issue or competing open PR found. Closed PR #1988 concerns a different helper, HTTPBody; this change is limited to HTTP status assertions.

Validation

Against master 87a7b9d57689f6579db2da795ab8deeab29cb724, using Go 1.27.3 on linux/amd64:

  • Before the fix, nil/empty helper regressions and the public status assertion regression failed.
  • Focused regression tests pass.
  • go test -p 2 -race -count=1 ./... passes.
  • go vet -p 2 ./... and go generate ./... pass; generation leaves no extra changes.
  • Go formatting, README formatting, and git diff --check pass.

AI-assisted using GPT-6 Astra

Keep existing query strings for nil or empty values. Preserve nonempty parameter replacement behavior and cover both helper and public assertion regressions.

AI-assisted implementation, testing, and automated review.
@JunaidAhamed-7777
JunaidAhamed-7777 marked this pull request as ready for review October 31, 2026 06:11
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