Skip to content

Commit 98eedc3

Browse files
committed
Don't redo the parsing on when normalizing the url.
1 parent e20f5fc commit 98eedc3

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lib/twingly/url.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@ def internal_parse(input)
7373
try_addressable_normalize(addressable_uri)
7474

7575
host = addressable_uri.host
76-
public_suffix_domain = PublicSuffix.parse(host, list: CUSTOM_PSL,
77-
default_rule: nil)
78-
raise Twingly::URL::Error::ParseError if public_suffix_domain.nil?
79-
80-
raise Twingly::URL::Error::ParseError if public_suffix_domain.sld.nil?
76+
public_suffix_domain = get_public_suffix_domain(addressable_uri.host)
8177

8278
new(addressable_uri, public_suffix_domain)
8379
rescue *ERRORS_TO_EXTEND => error
@@ -124,13 +120,21 @@ def valid_label?(label)
124120
label.match?(LETTERS_DIGITS_HYPHEN)
125121
end
126122

123+
def get_public_suffix_domain(host)
124+
public_suffix_domain = PublicSuffix.parse(host, list: CUSTOM_PSL, default_rule: nil)
125+
raise Twingly::URL::Error::ParseError if public_suffix_domain.nil?
126+
raise Twingly::URL::Error::ParseError if public_suffix_domain.sld.nil?
127+
public_suffix_domain
128+
end
129+
127130
private :new
128131
private :internal_parse
129132
private :clean_input
130133
private :strip_whitespace
131134
private :try_addressable_normalize
132135
private :valid_hostname?
133136
private :valid_label?
137+
private :get_public_suffix_domain
134138
end
135139

136140
def initialize(addressable_uri, public_suffix_domain)
@@ -189,7 +193,8 @@ def normalized
189193
normalized_url.host = normalized_host
190194
normalized_url.path = normalized_path
191195

192-
self.class.parse(normalized_url)
196+
public_suffix_domain = self.class.send(:get_public_suffix_domain, normalized_url.host)
197+
self.class.send(:new, normalized_url, public_suffix_domain)
193198
end
194199

195200
def normalized_scheme

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
end
1111

1212
config.order = :random
13+
config.filter_run_when_matching :focus
1314

1415
Kernel.srand config.seed
1516
end

0 commit comments

Comments
 (0)