weppos / publicsuffix-ruby

Domain name parser for Ruby based on the Public Suffix List.
https://simonecarletti.com/code/publicsuffix
MIT License
617 stars 109 forks source link

wrong result for IPv4 addresses #126

Closed idoa01 closed 7 years ago

idoa01 commented 7 years ago

It seems that PublicSuffix returns a bad result for IP addresses:

2.2.1 :001> PublicSuffix.domain("1.2.3.4")
 => "3.4"
2.2.1 :002> PublicSuffix.parse("1.2.3.4")
 => #<PublicSuffix::Domain:0x007fa21e3e54a0 @sld="3", @tld="4", @trd="1.2"> 
2.2.1 :003> PublicSuffix.valid?("1.2.3.4")
 => true
2.2.1 :004> PublicSuffix::VERSION
 => "2.0.4"

for me, the best result would be that PublicSuffix.domain("1.2.3.4") == "1.2.3.4"

But a DomainInvalid or a new DomainIsIP would also make more sense than the current behavior (and even more so since the leftmost byte is more important than the rightmost byte)

and if we are already on the subject, the behavior of PublicSuffix on IPv6 is:

2.2.1 :005> PublicSuffix.parse("[2001:db8:0:1234:0:567:8:1]")
PublicSuffix::DomainNotAllowed: `[2001:db8:0:1234:0:567:8:1]` is not allowed according to Registry policy

and for completeness, it might be best to throw the same error on IPv6 and IPv4 addresses.

weppos commented 7 years ago

The PSL doesn't deal with IP addresses at all. https://publicsuffix.org/

The scope of the PSL is to handle domain name suffixes. I'm not sure what you are trying to achieve, but if it involves IP addresses, then this library won't definitely be able to help you.