PublicSuffix 2.0 contains a rewritten internal representation and comparison logic, that drastically increases the lookup performance. The new version also changes several internal and external API.
This document documents the most relevant changes to help you upgrading from PublicSuffix 1.0 to 2.0.
*is assumed. You can override this behavior by passing a custom default rule with the
default_ruleoption. The old behavior can be restored by passing
PublicSuffix.domainis a new method that parses the input and returns the domain (combination of second level domain + suffix). This is a convenient helper to parse a domain name, for example when you need to determine the cookie or SSL scope.
private_domains: false). This feature also superseded the
private_domainsclass-level attribute, that is no longer available.
When upgrading, here’s the most relevant changes to keep an eye on:
Domain#valid?. You can easily obtain the same result by having a custom method that reconstructs the logic, and/or calling
PublicSuffix::List.private_domains is no longer available. Instead, you now have two ways to enable/disable the private domains:
PublicSuffix.domain("something.blogspot.com", ignore_private: true)
# Disable support for private TLDs PublicSuffix::List.default = PublicSuffix::List.parse(File.read(PublicSuffix::List::DEFAULT_LIST_PATH), private_domains: false) # => "blogspot.com" PublicSuffix.domain("something.blogspot.com") # => "blogspot.com"
Now that the library is 100% compliant with the official PublicSuffix algorithm, if a domain passed as input doesn’t match any rule, the wildcard rule
* is assumed. This means that unlisted TLDs will be considered valid by default, when they would have been invalid in 1.x. However, you can override this behavior to emulate the 1.x behavior if needed:
# 1.x: PublicSuffix.valid?("google.commm") # => false # 2.x: PublicSuffix.valid?("google.commm") # => true # Overriding 2.x behavior if needed: PublicSuffix.valid?("google.commm", default_rule: nil) # => false