Skip to content

Commit

Permalink
Merge 0e0bf27 into 5c04c79
Browse files Browse the repository at this point in the history
  • Loading branch information
isqad committed Apr 24, 2020
2 parents 5c04c79 + 0e0bf27 commit cdce690
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/addressable/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module CharacterClasses
"wais" => 210,
"ldap" => 389,
"prospero" => 1525
}
}.freeze

##
# Returns a URI object based on the parsed string.
Expand Down Expand Up @@ -463,7 +463,11 @@ def self.unencode(uri, return_type=String, leave_encoded='')
uri = uri.dup
# Seriously, only use UTF-8. I'm really not kidding!
uri.force_encoding("utf-8")
leave_encoded = leave_encoded.dup.force_encoding("utf-8")

unless leave_encoded.empty?
leave_encoded = leave_encoded.dup.force_encoding("utf-8")
end

result = uri.gsub(/%[0-9a-f]{2}/iu) do |sequence|
c = sequence[1..3].to_i(16).chr
c.force_encoding("utf-8")
Expand Down Expand Up @@ -554,7 +558,11 @@ def self.normalize_component(component, character_class=
end.flatten.join('|')})"
end

character_class = /[^#{character_class}]#{leave_re}/
character_class = if leave_re
/[^#{character_class}]#{leave_re}/
else
/[^#{character_class}]/
end
end
# We can't perform regexps on invalid UTF sequences, but
# here we need to, so switch to ASCII.
Expand Down Expand Up @@ -1114,6 +1122,7 @@ def host
# @return [String] The host component, normalized.
def normalized_host
return nil unless self.host

@normalized_host ||= begin
if !self.host.strip.empty?
result = ::Addressable::IDNA.to_ascii(
Expand All @@ -1132,7 +1141,9 @@ def normalized_host
end
end
# All normalized values should be UTF-8
@normalized_host.force_encoding(Encoding::UTF_8) if @normalized_host
if @normalized_host && !@normalized_host.empty?
@normalized_host.force_encoding(Encoding::UTF_8)
end
@normalized_host
end

Expand Down

0 comments on commit cdce690

Please sign in to comment.