Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with working with arrays of hashes in query #1053

Open
nulldef opened this issue Apr 9, 2024 · 0 comments
Open

Issue with working with arrays of hashes in query #1053

nulldef opened this issue Apr 9, 2024 · 0 comments

Comments

@nulldef
Copy link

nulldef commented Apr 9, 2024

I've discovered an issue with mock: It doesn't work if there is more than 1 nesting level of arrays of hashes in the request query string.

I discovered the issue appears in the lib/webmock/util/uri.rb file, line 19,20. Actually, it's a bit deeper (lib/webmock/util/query_mapper.rb#267), but things begin here.
So here is what I'm talking about:

query = "passengers[][discount][][code]=discount-code"
values = WebMock::Util::QueryMapper.query_to_values(query, notation: :subscript)
WebMock::Util::QueryMapper.values_to_query(values, notation: :subscript) # => "passengers%5B%5D[discount][0][code]=discount-code"

now the discount array has indexes inside while there is no index in the original query.

In real work it leads to some misleading things: the query performs without any indexes, but the mock has to contain the index just to be working.

What I suggest is to introduce two different notations instead of subscript – one with indexes and another without.

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

No branches or pull requests

1 participant