weppos / publicsuffix-ruby

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

.parse default behavior #110

Closed lastgabs closed 8 years ago

lastgabs commented 8 years ago

Heya

I've been using your gem (v 1.5) and today was thinking of updating to 2.0, so was doing some testing locally before I did the jump. I noticed that the parse class method no longer throws the DomainInvalid exception. However the documentation (http://www.rubydoc.info/gems/public_suffix/PublicSuffix.parse) has the following info:

(PublicSuffix::Error) — If domain is not a valid domain.
(PublicSuffix::DomainNotAllowed) — If a rule for domain is found, but the rule doesn't allow domain.

Is the code behaving strangely or is the documentation not yet fully updated?

Thanks!

weppos commented 8 years ago

Hi @lastgabs. #parse still throws that error, and the documentation is accurate. Here's an example:

2.3.1 :002 > PublicSuffix.parse("http://www.google.com")
PublicSuffix::DomainInvalid: http://www.google.com is not expected to contain a scheme
    from /Users/weppos/Code/publicsuffix-ruby/lib/public_suffix.rb:65:in `parse'
    from (irb):2
    from /Users/weppos/.rvm/rubies/ruby-2.3.1/bin/irb:11:in `<main>'

Please note that PublicSuffix::DomainInvalid is actually a descendant of PublicSuffix::Error, hence the documentation is correct (although perhaps a bit unfriendly). I'll update the docs to make sure it mentions PublicSuffix::DomainInvalid instead of PublicSuffix::Error.

Also please note that there is a big difference between v1 and v2 (make sure to read the upgrading docs) (relevant ticket #91, also #109).

It means if you expect the following code to raise an error

2.3.1 :003 > PublicSuffix.parse("www.google.invented")
 => #<PublicSuffix::Domain:0x007f86138d3650 @tld="invented", @sld="google", @trd="www">

this is no longer the case, as per the PSL requirement. You can enforce the library to ignore not assigned suffixes by passing a nil default_rule.