File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525 it 'returns the full host' do
2626 expect ( described_class . url_to_host_name ( 'https://news.bbc.co.uk/world' ) ) . to eq ( 'news.bbc.co.uk' )
2727 end
28+
29+ it 'returns nil for blank or invalid URLs' , :aggregate_failures do
30+ expect ( described_class . url_to_host_name ( nil ) ) . to be_nil
31+ expect ( described_class . url_to_host_name ( '' ) ) . to be_nil
32+ expect ( described_class . url_to_host_name ( 'not a url' ) ) . to be_nil
33+ end
34+ end
35+
36+ describe 'legacy naming guardrail' do
37+ it 'does not expose url_to_directory_name' do
38+ expect ( described_class ) . not_to respond_to ( :url_to_directory_name )
39+ end
40+ end
41+
42+ describe '.registrable_domain' do
43+ it 'falls back to host when PublicSuffix returns nil' do
44+ allow ( PublicSuffix ) . to receive ( :domain ) . with ( 'example.local' ) . and_return ( nil )
45+
46+ expect ( described_class . send ( :registrable_domain , 'example.local' ) ) . to eq ( 'example.local' )
47+ end
48+
49+ it 'falls back to host when PublicSuffix raises DomainInvalid' do
50+ allow ( PublicSuffix ) . to receive ( :domain ) . with ( 'invalid..host' )
51+ . and_raise ( PublicSuffix ::DomainInvalid )
52+
53+ expect ( described_class . send ( :registrable_domain , 'invalid..host' ) ) . to eq ( 'invalid..host' )
54+ end
2855 end
2956end
Original file line number Diff line number Diff line change 1010module Helper
1111 ##
1212 # @param url [String]
13- # @return [String]
13+ # @return [String, nil ]
1414 def self . url_to_registrable_domain ( url )
1515 host = url_to_host_name ( url )
1616 return host unless host
You can’t perform that action at this time.
0 commit comments