Repository navigation
Keep URI query in HTTPClient request signature when query is passed - #1145
Merged
bblimke merged 1 commit intoNov 20, 2026
Merged
Conversation
HTTPClient appends the query argument to any query already in the URI:
get("http://example.com/?a=1", {"b" => "2"}) requests /?a=1&b=2. The
HTTPClient adapter replaced the URI query with the query argument, so
the signature was /?b=2. With an empty hash it was /, dropping the
query completely. Stubs and expectations could then match a request
that was never made.
Combine the URI query with the query argument, like HTTPClient does.
The HTTPClient acceptance spec helper passed every query twice (in the
URI and as the query argument), which the old behaviour hid. It now
passes the query once, as the query argument.
Fixes bblimke#641
bblimke
added a commit
that referenced
this pull request
Nov 20, 2026
Drop a check that could not fail and explain the order of the query parts. The spec helper sends the query in the URI, as most callers do, so HTTPClient sends what the shared specs expect, and the adapter specs cover the query argument. Add a changelog entry.
Owner
|
Thank you @AmeenKhan12345! This is released in 3.36.0. |
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.
Fixes #641
Problem
With HTTPClient, you can put query params in the URL and also pass more in the
queryargument. HTTPClient sends both:WebMock doesn't record that URL. It drops the params that were already in the URL and keeps only the
queryargument:queryargument{ "b" => "2" }/Item?a=1&b=2/Item?b=2/Item?a=1&b=2{}/Item?a=1&/Item/Item?a=1nil/Item?a=1/Item?a=1/Item?a=1Because of this, stubs and
a_requestexpectations can match a URL that was never requested. Tests pass even though the real request is different.We ran into this in a real project. Our code passed
{}for every GET, and the URLs already had query params. An external API started rejecting those requests, but our tests kept passing, because WebMock recorded the URL with no query at all.Reproduction
Output on WebMock 3.34.0 with HTTPClient 2.10.0:
What this PR changes
queryargument to it, the same way HTTPClient does.queryargument. Real HTTPClient would send each param twice there; the bug above hid it. The helper now passes the query once, as thequeryargument.nil, plus a hash on a URL with no query. The first two fail without the fix.Tests
NO_CONNECTION=1).NO_CONNECTION=1): the only failures are 2 Patronget_fileexamples, which fail the same way onmasteron my machine.Note
A test that stubbed only the
queryargument part (for example?b=2, when the real request is?a=1&b=2) will stop matching after this change. That's expected, because the stub now has to match the URL that is really requested, but it may be worth a line in the changelog.The 2 failures on Ruby 3.3 / 3.4 / 4.0 are unrelated to this change. They're the Patron get_file specs, and they also fail on unmodified master with Patron 1.1.0, which was released after the last green master build (14 Oct).