Repository navigation
Parse arrays nested inside arrays of hashes in query params - #1144
Conversation
|
The two failing specs are This is the first build on the repo since 1.1.0 shipped, so the green ticks on the other open PRs all predate it. Locally the same two specs fail on clean master as well as on this branch, with an otherwise identical failure list. |
Use transform_values! in dehash, add a spec for an indexed array nested in an array of hashes in a form body, and document #1144 in the CHANGELOG, including what to do with stubs that use the old shape with "0", "1" keys, which WebMock's suggested stub printed.
|
Thank you @ihamzatarar! This is released in 3.36.0. While testing it I found a related bug, which I fixed on top: a nested key repeated under |
Fixes #1053.
A query with an array nested inside an array of hashes does not match a stub declared with the equivalent hash:
One level works (
query: {"a" => [{"b" => "1"}]}againsta[][b]=1), two levels do not. The reported request URL is also not the one the client sent:The
0is WebMock's own.WebMock::Util::URI.normalize_uriserialises the inner array with explicit indexes, andquery_to_valuescannot read them back:dehashturns a hash whose keys are all digits into an array, butnormalize_query_hashonly calls it when the top level value is aHash, anddehashonly recurses through hashes. An array nested inside an array element is never reached, so its numeric keys survive as a hash and the stub hash no longer compares equal.This changes the parsing side only. The serialised form still uses indexes below the first level, so there is no change to what
values_to_queryemits and no change to the notation question raised in #764.The same round trip was already lossy for a top level array of arrays, and that is fixed by the same change:
Three specs added: the parse case and the round trip in
query_mapper_spec.rb, and the matching case above inrequest_pattern_spec.rb. All three fail without the change.bundle exec rspec spec/unitpasses, 749 examples. The fullbundle exec rspec specgives 5688 examples and 144 failures, all inspec/acceptanceand all present unchanged on master here, where they need outbound network access.