Skip to content

Commit 435d9ad

Browse files
committed
Merge pull request #538 from davidbegin/extra-boolean-query-value-bug
prevents form adding an extra =true to urls
2 parents b18b029 + cc0be4e commit 435d9ad

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

lib/webmock/util/query_mapper.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def collect_query_parts(query)
7979
def collect_query_hash(query_array, empty_accumulator, options)
8080
query_array.compact.inject(empty_accumulator.dup) do |accumulator, (key, value)|
8181
value = if value.nil?
82-
true
82+
nil
8383
else
8484
::Addressable::URI.unencode_component(value.gsub(/\+/, ' '))
8585
end
@@ -263,6 +263,8 @@ def to_query(parent, value, options = {})
263263
buffer << "#{to_query(new_parent, val, options)}&"
264264
end
265265
buffer.chop
266+
when NilClass
267+
parent
266268
else
267269
encoded_value = Addressable::URI.encode_component(
268270
value.to_s.dup, Addressable::URI::CharacterClasses::UNRESERVED

spec/unit/util/query_mapper_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
context '#to_query' do
5454
it 'should transform nil value' do
55-
expect(subject.to_query('a', nil)).to eq('a=')
55+
expect(subject.to_query('a', nil)).to eq('a')
5656
end
5757
it 'should transform string value' do
5858
expect(subject.to_query('a', 'b')).to eq('a=b')

0 commit comments

Comments
 (0)