Permalink
Browse files

Add support for blank urls

  • Loading branch information...
1 parent a8585e6 commit 12d186dd58a28dfbee18229f22c9d43f7e39f82c Kevin Wang and Paul Elliott committed with Hashrocket Workstation Feb 13, 2012
Showing with 21 additions and 7 deletions.
  1. +1 −0 lib/domainatrix/domain_parser.rb
  2. +7 −7 lib/domainatrix/url.rb
  3. +13 −0 spec/domainatrix_spec.rb
@@ -31,6 +31,7 @@ def read_dat_file(file_name)
end
def parse(url)
+ return {} unless url && url.strip != ''
url = "http://#{url}" unless url[/:\/\//]
uri = URI.parse(url)
if uri.query
View
@@ -3,13 +3,13 @@ class Url
attr_reader :public_suffix, :domain, :subdomain, :path, :url, :scheme, :host
def initialize(attrs = {})
- @scheme = attrs[:scheme]
- @host = attrs[:host]
- @url = attrs[:url]
- @public_suffix = attrs[:public_suffix]
- @domain = attrs[:domain]
- @subdomain = attrs[:subdomain]
- @path = attrs[:path]
+ @scheme = attrs[:scheme] || ''
+ @host = attrs[:host] || ''
+ @url = attrs[:url] || ''
+ @public_suffix = attrs[:public_suffix] || ''
+ @domain = attrs[:domain] || ''
+ @subdomain = attrs[:subdomain] || ''
+ @path = attrs[:path] || ''
end
def canonical(options = {})
View
@@ -37,4 +37,17 @@
its(:path) { should == '' }
its(:domain_with_tld) { should == 'pauldix.net' }
end
+
+ context 'with a blank url' do
+ subject { Domainatrix.parse(nil) }
+ its(:scheme) { should == '' }
+ its(:host) { should == '' }
+ its(:url) { should == '' }
+ its(:public_suffix) { should == '' }
+ its(:domain) { should == '' }
+ its(:subdomain) { should == '' }
+ its(:path) { should == '' }
+ its(:domain_with_tld) { should == '' }
+ end
+
end

0 comments on commit 12d186d

Please sign in to comment.