diff --git a/lib/twingly/url.rb b/lib/twingly/url.rb index 3752ac0..83a734b 100644 --- a/lib/twingly/url.rb +++ b/lib/twingly/url.rb @@ -73,11 +73,7 @@ def internal_parse(input) try_addressable_normalize(addressable_uri) host = addressable_uri.host - public_suffix_domain = PublicSuffix.parse(host, list: CUSTOM_PSL, - default_rule: nil) - raise Twingly::URL::Error::ParseError if public_suffix_domain.nil? - - raise Twingly::URL::Error::ParseError if public_suffix_domain.sld.nil? + public_suffix_domain = get_public_suffix_domain(addressable_uri.host) new(addressable_uri, public_suffix_domain) rescue *ERRORS_TO_EXTEND => error @@ -124,6 +120,13 @@ def valid_label?(label) label.match?(LETTERS_DIGITS_HYPHEN) end + def get_public_suffix_domain(host) + public_suffix_domain = PublicSuffix.parse(host, list: CUSTOM_PSL, default_rule: nil) + raise Twingly::URL::Error::ParseError if public_suffix_domain.nil? + raise Twingly::URL::Error::ParseError if public_suffix_domain.sld.nil? + public_suffix_domain + end + private :new private :internal_parse private :clean_input @@ -131,6 +134,7 @@ def valid_label?(label) private :try_addressable_normalize private :valid_hostname? private :valid_label? + private :get_public_suffix_domain end def initialize(addressable_uri, public_suffix_domain) @@ -189,7 +193,8 @@ def normalized normalized_url.host = normalized_host normalized_url.path = normalized_path - self.class.parse(normalized_url) + public_suffix_domain = self.class.send(:get_public_suffix_domain, normalized_url.host) + self.class.send(:new, normalized_url, public_suffix_domain) end def normalized_scheme diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 61cec04..798ea87 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,6 +10,7 @@ end config.order = :random + config.filter_run_when_matching :focus Kernel.srand config.seed end