Skip to content

Commit fe31f2e

Browse files
authored
Skip empty key/value pairs. (#59)
1 parent cbb8ae2 commit fe31f2e

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/protocol/http/url.rb

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def self.encode(value, prefix = nil)
5858
# @parameter value [String] The unescaped key.
5959
def self.scan(string)
6060
string.split('&') do |assignment|
61+
next if assignment.empty?
62+
6163
key, value = assignment.split('=', 2)
6264

6365
yield unescape(key), value.nil? ? value : unescape(value)

test/protocol/http/url.rb

+5
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@
7676
Protocol::HTTP::URL.decode("=foo")
7777
end.to raise_exception(ArgumentError, message: be =~ /Invalid key/)
7878
end
79+
80+
it "fails with empty pairs" do
81+
expect(Protocol::HTTP::URL.decode("a=1&&b=2")).to be == {"a" => "1", "b" => "2"}
82+
expect(Protocol::HTTP::URL.decode("a&&b")).to be == {"a" => nil, "b" => nil}
83+
end
7984
end
8085

8186
with '.unescape' do

0 commit comments

Comments
 (0)