diff --git a/lib/rdf/model/uri.rb b/lib/rdf/model/uri.rb index e6deb7aa..f56391eb 100644 --- a/lib/rdf/model/uri.rb +++ b/lib/rdf/model/uri.rb @@ -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 diff --git a/spec/model_uri_spec.rb b/spec/model_uri_spec.rb index 8d00d7ba..4813d3b7 100644 --- a/spec/model_uri_spec.rb +++ b/spec/model_uri_spec.rb @@ -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