Skip to content

Commit

Permalink
Handling query params, which represent nested hashes with keys starti…
Browse files Browse the repository at this point in the history
…ng with non word characters.
  • Loading branch information
bblimke committed Apr 29, 2018
1 parent 332af13 commit 277da14
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/webmock/util/query_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def fill_accumulator_for_dot(accumulator, key, value)

def fill_accumulator_for_subscript(accumulator, key, value)
current_node = accumulator
subkeys = key.split(/(?=\[\w)/)
subkeys = key.split(/(?=\[[^\[\]]+)/)
subkeys[0..-2].each do |subkey|
node = subkey =~ /\[\]\z/ ? [] : {}
subkey = subkey.gsub(/[\[\]]/, '')
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/util/query_mapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
hsh = subject.query_to_values(query)
expect(hsh['a']).to eq('foo')
end

it "should parse hash query with key starting with non word character" do
query = "a[$in]=1".freeze
hsh = subject.query_to_values(query)
expect(hsh).to eql({'a' => {'$in' => '1'}})
end
end

context '#to_query' do
Expand Down

0 comments on commit 277da14

Please sign in to comment.