Repository navigation
Keep indexed query and form params in numeric order - #1141
Merged
Merged
Conversation
QueryMapper.dehash turned hashes with numeric keys into arrays by sorting the keys as strings, so a[10] came before a[2]. A stub with an array of more than ten elements in with(body:) or with(query:) didn't match a request that sent the same values with explicit indexes.
bblimke
added a commit
that referenced
this pull request
Nov 18, 2026
Sort indexed keys by number and then by text, so "01" and "1" always come out in the same order, as they did with the old text sort. sort_by is not stable, so the order of such keys depended on the order of the query. Check for digit keys with \A and \z, so a key with digits on just one of its lines stays a hash key instead of becoming index 0. Drop the redundant defined?(HTTP) from the http_rb adapter guard, use map in dehash, and add specs for indexed hashes in a query, for keys with leading zeros and for a key spanning lines. Document both PRs in the CHANGELOG, including what to do with stubs that list indexed values in the old order.
Owner
|
Thank you @afurm! This is released in 3.35.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.
When a form body or query string uses explicit indexes (
items[0][name]=...&items[1][name]=...), WebMock turns the numeric keys into an array, but it sorted them as strings. With 11 or more entriesitems[10]ends up right afteritems[1], so the parsed array is out of order and a stub declared with the same data doesn't match:WebMock::Util::QueryMapper.query_to_values(body)["items"]returnsitem0, item1, item10, item2, .... Indexed params like this are common with Rails nested attributes and other form encoders, and the same parsing is used forwith(query: ...).The fix sorts the keys by their integer value in
dehash. The keys are already known to be all digits at that point.I added specs to
query_mapper_spec.rbfor indexed arrays and indexed hashes, and a request pattern spec for the body case. They fail without the change, andbundle exec rspec spec/unitpasses (749 examples).