Skip to content

rewrite: scope keyed query replace to its named key - #7818

Merged
steadytao merged 3 commits into
caddyserver:masterfrom
alhudz:query-replace-key-scope
Jun 15, 2026
Merged

steadytao merged 3 commits into
caddyserver:masterfrom
alhudz:query-replace-key-scope

Conversation

@alhudz

@alhudz alhudz commented Jun 13, 2026 •

Copy link
Copy Markdown
Contributor

Repro: with query replace a foo bar, request /?a=foo&b=foo comes out as a=bar&b=bar; expected a=bar&b=foo.
Cause: the non-* branch of the Replace loop in queryOps.do ranges over every key and never uses the computed key, so it is an exact copy of the key == "*" branch and rewrites unrelated parameters.
Fix: scope the keyed branch to query[key], matching the Rename/Set/Add query ops and the headers module Replace. Added a table test covering the keyed, *, missing-key, and keyed search_regexp cases.

Assistance Disclosure

Used an LLM lightly to sanity-check the diff and the test cases; I wrote and verified the change myself.

@CLAassistant

CLAassistant commented Jun 13, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@steadytao

Copy link
Copy Markdown
Member

Thanks, the change seems right to me. The keyed query replace branch should only operate on query[key] while * remains the all-query-keys case.

Two things:

  • CLA is pending because the commit email is al.hudz.k@gmail.com; please add that email to your GitHub account or amend the commit to use an email associated with your account
  • Please add the standard Assistance Disclosure section to the PR body

You could also add one keyed search_regexp case to the tests as well since the implementation has a separate regexp replacement branch.

@alhudz

alhudz commented Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

CLA's green now. Added the disclosure to the PR body, and pushed a keyed search_regexp case: search_regexp f.o on key a against /?a=foo&b=foo gives a=bar&b=foo, so the regexp branch stays scoped to the named key too.

@francislavoie francislavoie added the bug 🐞 Something isn't working label Jun 14, 2026
@francislavoie francislavoie added this to the v2.11.5 milestone Jun 14, 2026

@steadytao steadytao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Keyed query replace now only mutates the named query key while * keeps the existing all-keys behaviour and the tests cover keyed, wildcard, missing-key, and regexp cases.

@steadytao
steadytao merged commit ae9bc02 into caddyserver:master Jun 15, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐞 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants