Merge pull request #15135 from Homebrew/dependabot/bundler/Library/Homebrew/addressable-2.8.2

build(deps): bump addressable from 2.8.1 to 2.8.2 in /Library/Homebrew
This commit is contained in:
Mike McQuaid 2023-04-04 15:37:46 +01:00 committed by GitHub
commit 0048a86673
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 141 additions and 321 deletions

View File

@ -7,7 +7,7 @@ GEM
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
addressable (2.8.1)
addressable (2.8.2)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
bindata (2.4.15)

View File

@ -10,13 +10,9 @@ module Addressable::IDNA
class << self
def to_ascii(input); end
def to_unicode(input); end
def unicode_normalize_kc(input); end
private
def lookup_unicode_combining_class(codepoint); end
def lookup_unicode_compatibility(codepoint); end
def lookup_unicode_composition(unpacked); end
def lookup_unicode_lowercase(codepoint); end
def punycode_adapt(delta, numpoints, firsttime); end
def punycode_basic?(codepoint); end
@ -25,28 +21,13 @@ module Addressable::IDNA
def punycode_delimiter?(codepoint); end
def punycode_encode(unicode); end
def punycode_encode_digit(d); end
def ucs4_to_utf8(char, buffer); end
def unicode_compose(unpacked); end
def unicode_compose_pair(ch_one, ch_two); end
def unicode_decompose(unpacked); end
def unicode_decompose_hangul(codepoint); end
def unicode_downcase(input); end
def unicode_sort_canonical(unpacked); end
end
end
Addressable::IDNA::ACE_MAX_LENGTH = T.let(T.unsafe(nil), Integer)
Addressable::IDNA::ACE_PREFIX = T.let(T.unsafe(nil), String)
Addressable::IDNA::COMPOSITION_TABLE = T.let(T.unsafe(nil), Hash)
Addressable::IDNA::HANGUL_LBASE = T.let(T.unsafe(nil), Integer)
Addressable::IDNA::HANGUL_LCOUNT = T.let(T.unsafe(nil), Integer)
Addressable::IDNA::HANGUL_NCOUNT = T.let(T.unsafe(nil), Integer)
Addressable::IDNA::HANGUL_SBASE = T.let(T.unsafe(nil), Integer)
Addressable::IDNA::HANGUL_SCOUNT = T.let(T.unsafe(nil), Integer)
Addressable::IDNA::HANGUL_TBASE = T.let(T.unsafe(nil), Integer)
Addressable::IDNA::HANGUL_TCOUNT = T.let(T.unsafe(nil), Integer)
Addressable::IDNA::HANGUL_VBASE = T.let(T.unsafe(nil), Integer)
Addressable::IDNA::HANGUL_VCOUNT = T.let(T.unsafe(nil), Integer)
Addressable::IDNA::PUNYCODE_BASE = T.let(T.unsafe(nil), Integer)
Addressable::IDNA::PUNYCODE_DAMP = T.let(T.unsafe(nil), Integer)
Addressable::IDNA::PUNYCODE_DELIMITER = T.let(T.unsafe(nil), Integer)
@ -226,6 +207,10 @@ class Addressable::URI
def split_path(path); end
def validate; end
private
def reset_ivs; end
class << self
def convert_path(path); end
def encode(uri, return_type = T.unsafe(nil)); end
@ -265,6 +250,7 @@ Addressable::URI::CharacterClasses::SUB_DELIMS = T.let(T.unsafe(nil), String)
Addressable::URI::CharacterClasses::UNRESERVED = T.let(T.unsafe(nil), String)
Addressable::URI::EMPTY_STR = T.let(T.unsafe(nil), String)
class Addressable::URI::InvalidURIError < ::StandardError; end
Addressable::URI::NONE = T.let(T.unsafe(nil), Object)
Addressable::URI::NORMPATH = T.let(T.unsafe(nil), Regexp)
module Addressable::URI::NormalizeCharacterClasses; end
Addressable::URI::NormalizeCharacterClasses::FRAGMENT = T.let(T.unsafe(nil), Regexp)

View File

@ -5018,8 +5018,6 @@ end
class Net::HTTPAlreadyReported
end
Net::HTTPClientError::EXCEPTION_TYPE = Net::HTTPServerException
Net::HTTPClientErrorCode = Net::HTTPClientError
class Net::HTTPEarlyHints
@ -5031,9 +5029,13 @@ end
Net::HTTPFatalErrorCode = Net::HTTPClientError
Net::HTTPInformation::EXCEPTION_TYPE = Net::HTTPError
class Net::HTTPInformation
end
Net::HTTPInformationCode = Net::HTTPInformation
Net::HTTPInformationCode::EXCEPTION_TYPE = Net::HTTPError
class Net::HTTPInformation
end
class Net::HTTPLoopDetected
HAS_BODY = ::T.let(nil, ::T.untyped)
@ -5081,8 +5083,6 @@ end
class Net::HTTPRangeNotSatisfiable
end
Net::HTTPRedirection::EXCEPTION_TYPE = Net::HTTPRetriableError
Net::HTTPRedirectionCode = Net::HTTPRedirection
Net::HTTPRequestURITooLarge = Net::HTTPURITooLong
@ -5091,15 +5091,17 @@ Net::HTTPResponceReceiver = Net::HTTPResponse
Net::HTTPRetriableCode = Net::HTTPRedirection
Net::HTTPServerError::EXCEPTION_TYPE = Net::HTTPFatalError
Net::HTTPServerErrorCode = Net::HTTPServerError
Net::HTTPSession = Net::HTTP
Net::HTTPSuccess::EXCEPTION_TYPE = Net::HTTPError
class Net::HTTPSuccess
end
Net::HTTPSuccessCode = Net::HTTPSuccess
Net::HTTPSuccessCode::EXCEPTION_TYPE = Net::HTTPError
class Net::HTTPSuccess
end
class Net::HTTPURITooLong
HAS_BODY = ::T.let(nil, ::T.untyped)

View File

@ -30,7 +30,7 @@ $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/zeitwerk-2.6.7/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/activesupport-6.1.7.3/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/public_suffix-5.0.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/addressable-2.8.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/addressable-2.8.2/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/ast-2.4.2/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/bindata-2.4.15/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/extensions/universal-darwin-21/#{Gem.extension_api_version}/msgpack-1.7.0")

View File

@ -29,10 +29,6 @@ module Addressable
IDN::Punycode.decode(value.to_s)
end
def self.unicode_normalize_kc(value)
IDN::Stringprep.nfkc_normalize(value.to_s)
end
def self.to_ascii(value)
value.to_s.split('.', -1).map do |segment|
if segment.size > 0 && segment.size < 64

View File

@ -66,7 +66,7 @@ module Addressable
# domain name as described in RFC 3490.
def self.to_ascii(input)
input = input.to_s unless input.is_a?(String)
input = input.dup
input = input.dup.force_encoding(Encoding::UTF_8).unicode_normalize(:nfkc)
if input.respond_to?(:force_encoding)
input.force_encoding(Encoding::ASCII_8BIT)
end
@ -77,7 +77,7 @@ module Addressable
part.force_encoding(Encoding::ASCII_8BIT)
end
if part =~ UTF8_REGEX && part =~ UTF8_REGEX_MULTIBYTE
ACE_PREFIX + punycode_encode(unicode_normalize_kc(part))
ACE_PREFIX + punycode_encode(part)
else
part
end
@ -112,15 +112,6 @@ module Addressable
output
end
# Unicode normalization form KC.
def self.unicode_normalize_kc(input)
input = input.to_s unless input.is_a?(String)
unpacked = input.unpack("U*")
unpacked =
unicode_compose(unicode_sort_canonical(unicode_decompose(unpacked)))
return unpacked.pack("U*")
end
##
# Unicode aware downcase method.
#
@ -136,164 +127,6 @@ module Addressable
end
private_class_method :unicode_downcase
def self.unicode_compose(unpacked)
unpacked_result = []
length = unpacked.length
return unpacked if length == 0
starter = unpacked[0]
starter_cc = lookup_unicode_combining_class(starter)
starter_cc = 256 if starter_cc != 0
for i in 1...length
ch = unpacked[i]
if (starter_cc == 0 &&
(composite = unicode_compose_pair(starter, ch)) != nil)
starter = composite
else
unpacked_result << starter
starter = ch
end
end
unpacked_result << starter
return unpacked_result
end
private_class_method :unicode_compose
def self.unicode_compose_pair(ch_one, ch_two)
if ch_one >= HANGUL_LBASE && ch_one < HANGUL_LBASE + HANGUL_LCOUNT &&
ch_two >= HANGUL_VBASE && ch_two < HANGUL_VBASE + HANGUL_VCOUNT
# Hangul L + V
return HANGUL_SBASE + (
(ch_one - HANGUL_LBASE) * HANGUL_VCOUNT + (ch_two - HANGUL_VBASE)
) * HANGUL_TCOUNT
elsif ch_one >= HANGUL_SBASE &&
ch_one < HANGUL_SBASE + HANGUL_SCOUNT &&
(ch_one - HANGUL_SBASE) % HANGUL_TCOUNT == 0 &&
ch_two >= HANGUL_TBASE && ch_two < HANGUL_TBASE + HANGUL_TCOUNT
# Hangul LV + T
return ch_one + (ch_two - HANGUL_TBASE)
end
p = []
ucs4_to_utf8(ch_one, p)
ucs4_to_utf8(ch_two, p)
return lookup_unicode_composition(p)
end
private_class_method :unicode_compose_pair
def self.ucs4_to_utf8(char, buffer)
if char < 128
buffer << char
elsif char < 2048
buffer << (char >> 6 | 192)
buffer << (char & 63 | 128)
elsif char < 0x10000
buffer << (char >> 12 | 224)
buffer << (char >> 6 & 63 | 128)
buffer << (char & 63 | 128)
elsif char < 0x200000
buffer << (char >> 18 | 240)
buffer << (char >> 12 & 63 | 128)
buffer << (char >> 6 & 63 | 128)
buffer << (char & 63 | 128)
elsif char < 0x4000000
buffer << (char >> 24 | 248)
buffer << (char >> 18 & 63 | 128)
buffer << (char >> 12 & 63 | 128)
buffer << (char >> 6 & 63 | 128)
buffer << (char & 63 | 128)
elsif char < 0x80000000
buffer << (char >> 30 | 252)
buffer << (char >> 24 & 63 | 128)
buffer << (char >> 18 & 63 | 128)
buffer << (char >> 12 & 63 | 128)
buffer << (char >> 6 & 63 | 128)
buffer << (char & 63 | 128)
end
end
private_class_method :ucs4_to_utf8
def self.unicode_sort_canonical(unpacked)
unpacked = unpacked.dup
i = 1
length = unpacked.length
return unpacked if length < 2
while i < length
last = unpacked[i-1]
ch = unpacked[i]
last_cc = lookup_unicode_combining_class(last)
cc = lookup_unicode_combining_class(ch)
if cc != 0 && last_cc != 0 && last_cc > cc
unpacked[i] = last
unpacked[i-1] = ch
i -= 1 if i > 1
else
i += 1
end
end
return unpacked
end
private_class_method :unicode_sort_canonical
def self.unicode_decompose(unpacked)
unpacked_result = []
for cp in unpacked
if cp >= HANGUL_SBASE && cp < HANGUL_SBASE + HANGUL_SCOUNT
l, v, t = unicode_decompose_hangul(cp)
unpacked_result << l
unpacked_result << v if v
unpacked_result << t if t
else
dc = lookup_unicode_compatibility(cp)
unless dc
unpacked_result << cp
else
unpacked_result.concat(unicode_decompose(dc.unpack("U*")))
end
end
end
return unpacked_result
end
private_class_method :unicode_decompose
def self.unicode_decompose_hangul(codepoint)
sindex = codepoint - HANGUL_SBASE;
if sindex < 0 || sindex >= HANGUL_SCOUNT
l = codepoint
v = t = nil
return l, v, t
end
l = HANGUL_LBASE + sindex / HANGUL_NCOUNT
v = HANGUL_VBASE + (sindex % HANGUL_NCOUNT) / HANGUL_TCOUNT
t = HANGUL_TBASE + sindex % HANGUL_TCOUNT
if t == HANGUL_TBASE
t = nil
end
return l, v, t
end
private_class_method :unicode_decompose_hangul
def self.lookup_unicode_combining_class(codepoint)
codepoint_data = UNICODE_DATA[codepoint]
(codepoint_data ?
(codepoint_data[UNICODE_DATA_COMBINING_CLASS] || 0) :
0)
end
private_class_method :lookup_unicode_combining_class
def self.lookup_unicode_compatibility(codepoint)
codepoint_data = UNICODE_DATA[codepoint]
(codepoint_data ?
codepoint_data[UNICODE_DATA_COMPATIBILITY] : nil)
end
private_class_method :lookup_unicode_compatibility
def self.lookup_unicode_lowercase(codepoint)
codepoint_data = UNICODE_DATA[codepoint]
(codepoint_data ?
@ -302,21 +135,6 @@ module Addressable
end
private_class_method :lookup_unicode_lowercase
def self.lookup_unicode_composition(unpacked)
return COMPOSITION_TABLE[unpacked]
end
private_class_method :lookup_unicode_composition
HANGUL_SBASE = 0xac00
HANGUL_LBASE = 0x1100
HANGUL_LCOUNT = 19
HANGUL_VBASE = 0x1161
HANGUL_VCOUNT = 21
HANGUL_TBASE = 0x11a7
HANGUL_TCOUNT = 28
HANGUL_NCOUNT = HANGUL_VCOUNT * HANGUL_TCOUNT # 588
HANGUL_SCOUNT = HANGUL_LCOUNT * HANGUL_NCOUNT # 11172
UNICODE_DATA_COMBINING_CLASS = 0
UNICODE_DATA_EXCLUSION = 1
UNICODE_DATA_CANONICAL = 2

View File

@ -892,7 +892,7 @@ module Addressable
# operator.
#
# @param [Hash, Array, String] value
# Normalizes keys and values with IDNA#unicode_normalize_kc
# Normalizes unicode keys and values with String#unicode_normalize (NFC)
#
# @return [Hash, Array, String] The normalized values
def normalize_value(value)
@ -902,15 +902,17 @@ module Addressable
# Handle unicode normalization
if value.kind_of?(Array)
value.map! { |val| Addressable::IDNA.unicode_normalize_kc(val) }
value.map! { |val| normalize_value(val) }
elsif value.kind_of?(Hash)
value = value.inject({}) { |acc, (k, v)|
acc[Addressable::IDNA.unicode_normalize_kc(k)] =
Addressable::IDNA.unicode_normalize_kc(v)
acc[normalize_value(k)] = normalize_value(v)
acc
}
else
value = Addressable::IDNA.unicode_normalize_kc(value)
if value.encoding != Encoding::UTF_8
value = value.dup.force_encoding(Encoding::UTF_8)
end
value = value.unicode_normalize(:nfc)
end
value
end

View File

@ -53,7 +53,7 @@ module Addressable
PCHAR = (UNRESERVED + SUB_DELIMS + "\\:\\@").freeze
SCHEME = (ALPHA + DIGIT + "\\-\\+\\.").freeze
HOST = (UNRESERVED + SUB_DELIMS + "\\[\\:\\]").freeze
AUTHORITY = (PCHAR + "\\[\\:\\]").freeze
AUTHORITY = (PCHAR + "\\[\\]").freeze
PATH = (PCHAR + "\\/").freeze
QUERY = (PCHAR + "\\/\\?").freeze
FRAGMENT = (PCHAR + "\\/\\?").freeze
@ -117,7 +117,7 @@ module Addressable
uri = uri.to_str
rescue TypeError, NoMethodError
raise TypeError, "Can't convert #{uri.class} into String."
end if not uri.is_a? String
end unless uri.is_a?(String)
# This Regexp supplied as an example in RFC 3986, and it works great.
scan = uri.scan(URIREGEX)
@ -138,15 +138,15 @@ module Addressable
user = userinfo.strip[/^([^:]*):?/, 1]
password = userinfo.strip[/:(.*)$/, 1]
end
host = authority.sub(
/^([^\[\]]*)@/, EMPTY_STR
).sub(
/:([^:@\[\]]*?)$/, EMPTY_STR
)
port = authority[/:([^:@\[\]]*?)$/, 1]
end
if port == EMPTY_STR
port = nil
port = nil if port == EMPTY_STR
end
return new(
@ -189,7 +189,7 @@ module Addressable
uri = uri.to_s
end
if !uri.respond_to?(:to_str)
unless uri.respond_to?(:to_str)
raise TypeError, "Can't convert #{uri.class} into String."
end
# Otherwise, convert to a String
@ -281,7 +281,7 @@ module Addressable
return nil unless path
# If a URI object is passed, just return itself.
return path if path.kind_of?(self)
if !path.respond_to?(:to_str)
unless path.respond_to?(:to_str)
raise TypeError, "Can't convert #{path.class} into String."
end
# Otherwise, convert to a String
@ -329,13 +329,13 @@ module Addressable
# #=> #<Addressable::URI:0xcab390 URI:http://example.com/relative/path>
def self.join(*uris)
uri_objects = uris.collect do |uri|
if !uri.respond_to?(:to_str)
unless uri.respond_to?(:to_str)
raise TypeError, "Can't convert #{uri.class} into String."
end
uri.kind_of?(self) ? uri : self.parse(uri.to_str)
end
result = uri_objects.shift.dup
for uri in uri_objects
uri_objects.each do |uri|
result.join!(uri)
end
return result
@ -481,7 +481,7 @@ module Addressable
leave_encoded.include?(c) ? sequence : c
end
result.force_encoding("utf-8")
result.force_encoding(Encoding::UTF_8)
if return_type == String
return result
elsif return_type == ::Addressable::URI
@ -579,7 +579,7 @@ module Addressable
unencoded = self.unencode_component(component, String, leave_encoded)
begin
encoded = self.encode_component(
Addressable::IDNA.unicode_normalize_kc(unencoded),
unencoded.unicode_normalize(:nfc),
character_class,
leave_encoded
)
@ -687,8 +687,7 @@ module Addressable
components.each do |key, value|
if value != nil
begin
components[key] =
Addressable::IDNA.unicode_normalize_kc(value.to_str)
components[key] = value.to_str.unicode_normalize(:nfc)
rescue ArgumentError
# Likely a malformed UTF-8 character, skip unicode normalization
components[key] = value.to_str
@ -836,7 +835,9 @@ module Addressable
end
end
self.defer_validation do
reset_ivs
defer_validation do
# Bunch of crazy logic required because of the composite components
# like userinfo and authority.
self.scheme = options[:scheme] if options[:scheme]
@ -851,7 +852,8 @@ module Addressable
self.query_values = options[:query_values] if options[:query_values]
self.fragment = options[:fragment] if options[:fragment]
end
self.to_s
to_s # force path validation
end
##
@ -878,9 +880,7 @@ module Addressable
# The scheme component for this URI.
#
# @return [String] The scheme component.
def scheme
return defined?(@scheme) ? @scheme : nil
end
attr_reader :scheme
##
# The scheme component for this URI, normalized.
@ -888,8 +888,8 @@ module Addressable
# @return [String] The scheme component, normalized.
def normalized_scheme
return nil unless self.scheme
@normalized_scheme ||= begin
if self.scheme =~ /^\s*ssh\+svn\s*$/i
if @normalized_scheme == NONE
@normalized_scheme = if self.scheme =~ /^\s*ssh\+svn\s*$/i
"svn+ssh".dup
else
Addressable::URI.normalize_component(
@ -920,7 +920,7 @@ module Addressable
@scheme = nil if @scheme.to_s.strip.empty?
# Reset dependent values
remove_instance_variable(:@normalized_scheme) if defined?(@normalized_scheme)
@normalized_scheme = NONE
remove_composite_values
# Ensure we haven't created an invalid URI
@ -931,9 +931,7 @@ module Addressable
# The user component for this URI.
#
# @return [String] The user component.
def user
return defined?(@user) ? @user : nil
end
attr_reader :user
##
# The user component for this URI, normalized.
@ -941,8 +939,8 @@ module Addressable
# @return [String] The user component, normalized.
def normalized_user
return nil unless self.user
return @normalized_user if defined?(@normalized_user)
@normalized_user ||= begin
return @normalized_user unless @normalized_user == NONE
@normalized_user = begin
if normalized_scheme =~ /https?/ && self.user.strip.empty? &&
(!self.password || self.password.strip.empty?)
nil
@ -970,14 +968,14 @@ module Addressable
# You can't have a nil user with a non-nil password
if password != nil
@user = EMPTY_STR if @user.nil?
@user = EMPTY_STR unless user
end
# Reset dependent values
remove_instance_variable(:@userinfo) if defined?(@userinfo)
remove_instance_variable(:@normalized_userinfo) if defined?(@normalized_userinfo)
remove_instance_variable(:@authority) if defined?(@authority)
remove_instance_variable(:@normalized_user) if defined?(@normalized_user)
@userinfo = nil
@normalized_userinfo = NONE
@authority = nil
@normalized_user = NONE
remove_composite_values
# Ensure we haven't created an invalid URI
@ -988,9 +986,7 @@ module Addressable
# The password component for this URI.
#
# @return [String] The password component.
def password
return defined?(@password) ? @password : nil
end
attr_reader :password
##
# The password component for this URI, normalized.
@ -998,8 +994,8 @@ module Addressable
# @return [String] The password component, normalized.
def normalized_password
return nil unless self.password
return @normalized_password if defined?(@normalized_password)
@normalized_password ||= begin
return @normalized_password unless @normalized_password == NONE
@normalized_password = begin
if self.normalized_scheme =~ /https?/ && self.password.strip.empty? &&
(!self.user || self.user.strip.empty?)
nil
@ -1026,17 +1022,15 @@ module Addressable
@password = new_password ? new_password.to_str : nil
# You can't have a nil user with a non-nil password
@password ||= nil
@user ||= nil
if @password != nil
@user = EMPTY_STR if @user.nil?
self.user = EMPTY_STR if user.nil?
end
# Reset dependent values
remove_instance_variable(:@userinfo) if defined?(@userinfo)
remove_instance_variable(:@normalized_userinfo) if defined?(@normalized_userinfo)
remove_instance_variable(:@authority) if defined?(@authority)
remove_instance_variable(:@normalized_password) if defined?(@normalized_password)
@userinfo = nil
@normalized_userinfo = NONE
@authority = nil
@normalized_password = NONE
remove_composite_values
# Ensure we haven't created an invalid URI
@ -1066,8 +1060,8 @@ module Addressable
# @return [String] The userinfo component, normalized.
def normalized_userinfo
return nil unless self.userinfo
return @normalized_userinfo if defined?(@normalized_userinfo)
@normalized_userinfo ||= begin
return @normalized_userinfo unless @normalized_userinfo == NONE
@normalized_userinfo = begin
current_user = self.normalized_user
current_password = self.normalized_password
if !current_user && !current_password
@ -1105,7 +1099,7 @@ module Addressable
self.user = new_user
# Reset dependent values
remove_instance_variable(:@authority) if defined?(@authority)
@authority = nil
remove_composite_values
# Ensure we haven't created an invalid URI
@ -1116,9 +1110,7 @@ module Addressable
# The host component for this URI.
#
# @return [String] The host component.
def host
return defined?(@host) ? @host : nil
end
attr_reader :host
##
# The host component for this URI, normalized.
@ -1161,8 +1153,8 @@ module Addressable
@host = new_host ? new_host.to_str : nil
# Reset dependent values
remove_instance_variable(:@authority) if defined?(@authority)
remove_instance_variable(:@normalized_host) if defined?(@normalized_host)
@authority = nil
@normalized_host = nil
remove_composite_values
# Ensure we haven't created an invalid URI
@ -1293,14 +1285,14 @@ module Addressable
end
# Password assigned first to ensure validity in case of nil
self.password = defined?(new_password) ? new_password : nil
self.user = defined?(new_user) ? new_user : nil
self.host = defined?(new_host) ? new_host : nil
self.port = defined?(new_port) ? new_port : nil
self.password = new_password
self.user = new_user
self.host = new_host
self.port = new_port
# Reset dependent values
remove_instance_variable(:@userinfo) if defined?(@userinfo)
remove_instance_variable(:@normalized_userinfo) if defined?(@normalized_userinfo)
@userinfo = nil
@normalized_userinfo = NONE
remove_composite_values
# Ensure we haven't created an invalid URI
@ -1348,16 +1340,16 @@ module Addressable
new_port = new_origin[/:([^:@\[\]\/]*?)$/, 1]
end
self.scheme = defined?(new_scheme) ? new_scheme : nil
self.host = defined?(new_host) ? new_host : nil
self.port = defined?(new_port) ? new_port : nil
self.scheme = new_scheme
self.host = new_host
self.port = new_port
self.userinfo = nil
# Reset dependent values
remove_instance_variable(:@userinfo) if defined?(@userinfo)
remove_instance_variable(:@normalized_userinfo) if defined?(@normalized_userinfo)
remove_instance_variable(:@authority) if defined?(@authority)
remove_instance_variable(:@normalized_authority) if defined?(@normalized_authority)
@userinfo = nil
@normalized_userinfo = NONE
@authority = nil
@normalized_authority = nil
remove_composite_values
# Ensure we haven't created an invalid URI
@ -1384,9 +1376,7 @@ module Addressable
# infer port numbers from default values.
#
# @return [Integer] The port component.
def port
return defined?(@port) ? @port : nil
end
attr_reader :port
##
# The port component for this URI, normalized.
@ -1394,8 +1384,8 @@ module Addressable
# @return [Integer] The port component, normalized.
def normalized_port
return nil unless self.port
return @normalized_port if defined?(@normalized_port)
@normalized_port ||= begin
return @normalized_port unless @normalized_port == NONE
@normalized_port = begin
if URI.port_mapping[self.normalized_scheme] == self.port
nil
else
@ -1426,8 +1416,8 @@ module Addressable
@port = nil if @port == 0
# Reset dependent values
remove_instance_variable(:@authority) if defined?(@authority)
remove_instance_variable(:@normalized_port) if defined?(@normalized_port)
@authority = nil
@normalized_port = NONE
remove_composite_values
# Ensure we haven't created an invalid URI
@ -1528,9 +1518,7 @@ module Addressable
# The path component for this URI.
#
# @return [String] The path component.
def path
return defined?(@path) ? @path : EMPTY_STR
end
attr_reader :path
NORMPATH = /^(?!\/)[^\/:]*:.*$/
##
@ -1579,7 +1567,7 @@ module Addressable
end
# Reset dependent values
remove_instance_variable(:@normalized_path) if defined?(@normalized_path)
@normalized_path = nil
remove_composite_values
# Ensure we haven't created an invalid URI
@ -1609,9 +1597,7 @@ module Addressable
# The query component for this URI.
#
# @return [String] The query component.
def query
return defined?(@query) ? @query : nil
end
attr_reader :query
##
# The query component for this URI, normalized.
@ -1619,8 +1605,8 @@ module Addressable
# @return [String] The query component, normalized.
def normalized_query(*flags)
return nil unless self.query
return @normalized_query if defined?(@normalized_query)
@normalized_query ||= begin
return @normalized_query unless @normalized_query == NONE
@normalized_query = begin
modified_query_class = Addressable::URI::CharacterClasses::QUERY.dup
# Make sure possible key-value pair delimiters are escaped.
modified_query_class.sub!("\\&", "").sub!("\\;", "")
@ -1652,7 +1638,7 @@ module Addressable
@query = new_query ? new_query.to_str : nil
# Reset dependent values
remove_instance_variable(:@normalized_query) if defined?(@normalized_query)
@normalized_query = NONE
remove_composite_values
end
@ -1814,9 +1800,7 @@ module Addressable
# The fragment component for this URI.
#
# @return [String] The fragment component.
def fragment
return defined?(@fragment) ? @fragment : nil
end
attr_reader :fragment
##
# The fragment component for this URI, normalized.
@ -1824,8 +1808,8 @@ module Addressable
# @return [String] The fragment component, normalized.
def normalized_fragment
return nil unless self.fragment
return @normalized_fragment if defined?(@normalized_fragment)
@normalized_fragment ||= begin
return @normalized_fragment unless @normalized_fragment == NONE
@normalized_fragment = begin
component = Addressable::URI.normalize_component(
self.fragment,
Addressable::URI::NormalizeCharacterClasses::FRAGMENT
@ -1848,7 +1832,7 @@ module Addressable
@fragment = new_fragment ? new_fragment.to_str : nil
# Reset dependent values
remove_instance_variable(:@normalized_fragment) if defined?(@normalized_fragment)
@normalized_fragment = NONE
remove_composite_values
# Ensure we haven't created an invalid URI
@ -2014,7 +1998,7 @@ module Addressable
#
# @see Hash#merge
def merge(hash)
if !hash.respond_to?(:to_hash)
unless hash.respond_to?(:to_hash)
raise TypeError, "Can't convert #{hash.class} into Hash."
end
hash = hash.to_hash
@ -2408,7 +2392,8 @@ module Addressable
yield
@validation_deferred = false
validate
return nil
ensure
@validation_deferred = false
end
protected
@ -2507,11 +2492,7 @@ module Addressable
# @return [Addressable::URI] <code>self</code>.
def replace_self(uri)
# Reset dependent values
instance_variables.each do |var|
if instance_variable_defined?(var) && var != :@validation_deferred
remove_instance_variable(var)
end
end
reset_ivs
@scheme = uri.scheme
@user = uri.user
@ -2543,8 +2524,8 @@ module Addressable
#
# @api private
def remove_composite_values
remove_instance_variable(:@uri_string) if defined?(@uri_string)
remove_instance_variable(:@hash) if defined?(@hash)
@uri_string = nil
@hash = nil
end
##
@ -2556,5 +2537,40 @@ module Addressable
str.force_encoding(Encoding::UTF_8)
end
end
private
##
# Resets instance variables
#
# @api private
def reset_ivs
@scheme = nil
@user = nil
@normalized_scheme = NONE
@normalized_user = NONE
@uri_string = nil
@hash = nil
@userinfo = nil
@normalized_userinfo = NONE
@authority = nil
@password = nil
@normalized_authority = nil
@port = nil
@normalized_password = NONE
@host = nil
@normalized_host = nil
@normalized_port = NONE
@path = EMPTY_STR
@normalized_path = nil
@normalized_query = NONE
@fragment = nil
@normalized_fragment = NONE
@query = nil
end
NONE = Object.new.freeze
private_constant :NONE
end
end

View File

@ -23,7 +23,7 @@ if !defined?(Addressable::VERSION)
module VERSION
MAJOR = 2
MINOR = 8
TINY = 1
TINY = 2
STRING = [MAJOR, MINOR, TINY].join('.')
end