Skip to content

Keep blank values when matching query parameters - #188

Closed
xiehuanyi wants to merge 1 commit into
h2non:masterfrom
xiehuanyi:fix/blank-query-parameters-20261008
Closed

xiehuanyi wants to merge 1 commit into
h2non:masterfrom
xiehuanyi:fix/blank-query-parameters-20261008

Conversation

@xiehuanyi

Copy link
Copy Markdown

Description

QueryMatcher drops empty query values during parsing. A dictionary expectation such as {"cursor": ""} rejects ?cursor=, while the equivalent string expectation becomes an empty dictionary and can incorrectly match requests with a different cursor or no cursor.

Keep blank values when parsing both expectations and request queries. Document that an expected empty value requires the parameter to be present. The regression tests cover dictionary and string expectations, missing and different parameters, and real mocked HTTP requests.

Fixes #181. This applies the keep_blank_values approach suggested by plaes.

Validation: seven new cases fail on unmodified master; the full suite passes 247 tests with three existing expected failures on Python 3.14.6 / pytest 8.4.2. Complete Ruff lint/format checks and the configured interceptor Mypy check pass. aiohttp 3.13.3 and urllib3 2.5.0 were used, within the declared ranges. Since port 8080 is occupied locally, an external test plugin binds the existing responder fixture to an ephemeral port and adjusts its fixture URL, including child pytest processes; no upstream assertions or fixture source were changed for this adjustment. Other interpreter/dependency versions were not run locally.

Developed, reviewed, and tested with AI assistance.

PR Checklist

  • I've added tests for any code changes
  • I've documented the affected parameter behavior

Copilot AI balanced review requested due to automatic review settings October 8, 2026 11:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@xiehuanyi xiehuanyi closed this Oct 10, 2026
jharibo added a commit to jharibo/pookx that referenced this pull request Oct 21, 2026
parse_qs drops empty values by default, so param("x", "") never matched
?x=, and a mock for ?x= matched any query. Patch suggested in
h2non#181; docs and tests taken from h2non#188.

Co-authored-by: Priit Laes <91895+plaes@users.noreply.github.com>
Co-authored-by: Huanyi Xie <74809554+xiehuanyi@users.noreply.github.com>
@jharibo

jharibo commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this. I've adopted it in pookx, a maintained fork, released in 2.2.2 with you credited as co-author on the commit. See #186 for the background.

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.

Query param matching with empty values?

3 participants