Skip to content

Commit

Permalink
Skip empty key/value pairs. (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix authored Jul 7, 2024
1 parent cbb8ae2 commit fe31f2e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/protocol/http/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def self.encode(value, prefix = nil)
# @parameter value [String] The unescaped key.
def self.scan(string)
string.split('&') do |assignment|
next if assignment.empty?

key, value = assignment.split('=', 2)

yield unescape(key), value.nil? ? value : unescape(value)
Expand Down
5 changes: 5 additions & 0 deletions test/protocol/http/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
Protocol::HTTP::URL.decode("=foo")
end.to raise_exception(ArgumentError, message: be =~ /Invalid key/)
end

it "fails with empty pairs" do
expect(Protocol::HTTP::URL.decode("a=1&&b=2")).to be == {"a" => "1", "b" => "2"}
expect(Protocol::HTTP::URL.decode("a&&b")).to be == {"a" => nil, "b" => nil}
end
end

with '.unescape' do
Expand Down

0 comments on commit fe31f2e

Please sign in to comment.