Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added additional test case and fix for issue with valid? returning ni…

…l in some cases
  • Loading branch information...
commit b5fbb7fee9e26782f70ad8dc5c324afc1075f42c 1 parent 9efdda4
@dparis dparis authored
Showing with 15 additions and 1 deletion.
  1. +11 −1 lib/postrank-uri.rb
  2. +4 −0 spec/postrank-uri_spec.rb
View
12 lib/postrank-uri.rb
@@ -216,8 +216,18 @@ def parse(uri, opts = {})
end
def valid?(uri)
+ # URI is only valid if it is not nil, parses cleanly as a URI,
+ # and the domain has a recognized, valid TLD component
+ return false if uri.nil?
+
+ is_valid = false
cleaned_uri = clean(uri, :raw => true)
- cleaned_uri && cleaned_uri.host && PublicSuffix.valid?(cleaned_uri.host)
+
+ if host = cleaned_uri.host
+ is_valid = PublicSuffix.valid?(host)
+ end
+
+ is_valid
end
end
end
View
4 spec/postrank-uri_spec.rb
@@ -339,6 +339,10 @@ def e(text)
end
context 'valid?' do
+ it 'marks incomplete URI string as invalid' do
+ PostRank::URI.valid?('/path/page.html').should be_false
+ end
+
it 'marks www.test.c as invalid' do
PostRank::URI.valid?('http://www.test.c').should be_false
end
Please sign in to comment.
Something went wrong with that request. Please try again.