Skip to content

Commit

Permalink
Fix problem parsing ill-formed URI query parameters such as "?&a".
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Oct 2, 2023
1 parent 8864eac commit 365dd36
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
21 changes: 11 additions & 10 deletions lib/rdf/model/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1240,17 +1240,18 @@ def query_values(return_type=Hash)
query.to_s.split('&').
inject(return_type == Hash ? {} : []) do |memo,kv|
k,v = kv.to_s.split('=', 2)
next if k.to_s.empty?
k = CGI.unescape(k)
v = CGI.unescape(v) if v
if return_type == Hash
case memo[k]
when nil then memo[k] = v
when Array then memo[k] << v
else memo[k] = [memo[k], v]
unless k.to_s.empty?
k = CGI.unescape(k)
v = CGI.unescape(v) if v
if return_type == Hash
case memo[k]
when nil then memo[k] = v
when Array then memo[k] << v
else memo[k] = [memo[k], v]
end
else
memo << [k, v].compact
end
else
memo << [k, v].compact
end
memo
end
Expand Down
1 change: 1 addition & 0 deletions spec/model_uri_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@
"?one.two.three=four" => {"one.two.three" => "four"},
"?one[two][three]=four&one[two][five]=six" => {"one[two][three]" => "four", "one[two][five]" => "six"},
"?one=two&one=three&one=four" => {'one' => ['two', 'three', 'four']},
"?&a" => {'a' => nil},
}.each do |uri, result|
it uri do
if result
Expand Down

0 comments on commit 365dd36

Please sign in to comment.