lib/httpx/domain_name.rb in httpx-0.24.7 vs lib/httpx/domain_name.rb in httpx-1.0.0

- old
+ new

@@ -49,54 +49,52 @@ # may be nil if the hostname does not have one, like when it is an # IP address, an effective TLD or higher itself, or of a # non-canonical domain. attr_reader :domain - DOT = "." # :nodoc: - class << self def new(domain) return domain if domain.is_a?(self) super(domain) end # Normalizes a _domain_ using the Punycode algorithm as necessary. # The result will be a downcased, ASCII-only string. def normalize(domain) - domain = domain.chomp(DOT).unicode_normalize(:nfc) unless domain.ascii_only? + domain = domain.chomp(".").unicode_normalize(:nfc) unless domain.ascii_only? Punycode.encode_hostname(domain).downcase end end # Parses _hostname_ into a DomainName object. An IP address is also # accepted. An IPv6 address may be enclosed in square brackets. def initialize(hostname) hostname = String(hostname) - raise ArgumentError, "domain name must not start with a dot: #{hostname}" if hostname.start_with?(DOT) + raise ArgumentError, "domain name must not start with a dot: #{hostname}" if hostname.start_with?(".") begin @ipaddr = IPAddr.new(hostname) @hostname = @ipaddr.to_s return rescue IPAddr::Error nil end @hostname = DomainName.normalize(hostname) - tld = if (last_dot = @hostname.rindex(DOT)) + tld = if (last_dot = @hostname.rindex(".")) @hostname[(last_dot + 1)..-1] else @hostname end # unknown/local TLD @domain = if last_dot # fallback - accept cookies down to second level # cf. http://www.dkim-reputation.org/regdom-libs/ - if (penultimate_dot = @hostname.rindex(DOT, last_dot - 1)) + if (penultimate_dot = @hostname.rindex(".", last_dot - 1)) @hostname[(penultimate_dot + 1)..-1] else @hostname end else @@ -124,20 +122,15 @@ # RFC 6265 #4.1.1 # Domain-value must be a subdomain. @domain && self <= domain && domain <= @domain end - # def ==(other) - # other = DomainName.new(other) - # other.hostname == @hostname - # end - def <=>(other) other = DomainName.new(other) othername = other.hostname if othername == @hostname 0 - elsif @hostname.end_with?(othername) && @hostname[-othername.size - 1, 1] == DOT + elsif @hostname.end_with?(othername) && @hostname[-othername.size - 1, 1] == "." # The other is higher -1 else # The other is lower 1