Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/addressable/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1675,21 +1675,26 @@ def query_values(return_type=Hash)
raise ArgumentError, "Invalid return type. Must be Hash or Array."
end
return nil if self.query == nil
query_scheme = normalized_scheme
form_encoded = query_scheme.nil? ||
query_scheme == "http" || query_scheme == "https"
split_query = self.query.split("&").map do |pair|
pair.split("=", 2) if pair && !pair.empty?
end.compact
return split_query.inject(empty_accumulator.dup) do |accu, pair|
# I'd rather use key/value identifiers instead of array lookups,
# but in this case I really want to maintain the exact pair structure,
# so it's best to make all changes in-place.
pair[0] = URI.unencode_component(pair[0])
key = pair[0]
key = key.tr("+", " ") if form_encoded
pair[0] = URI.unencode_component(key)
if pair[1].respond_to?(:to_str)
value = pair[1].to_str
# I loathe the fact that I have to do this. Stupid HTML 4.01.
# Treating '+' as a space was just an unbelievably bad idea.
# There was nothing wrong with '%20'!
# If it ain't broke, don't fix it!
value = value.tr("+", " ") if ["http", "https", nil].include?(scheme)
value = value.tr("+", " ") if form_encoded
pair[1] = URI.unencode_component(value)
end
if return_type == Hash
Expand Down