Skip to content

Commit

Permalink
Merge pull request #11 from swiftype/master
Browse files Browse the repository at this point in the history
Make PostRank::URI.valid? work with punycode and Unicode domain names
  • Loading branch information
igrigorik committed May 8, 2013
2 parents 707b7c0 + ab96afc commit 2b93565
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/postrank-uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def valid?(uri)
cleaned_uri = clean(uri, :raw => true)

if host = cleaned_uri.host
is_valid = PublicSuffix.valid?(host)
is_valid = PublicSuffix.valid?(Addressable::IDNA.to_unicode(host))
end

is_valid
Expand Down
8 changes: 8 additions & 0 deletions spec/postrank-uri_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,5 +350,13 @@ def e(text)
it 'marks www.test.com as valid' do
PostRank::URI.valid?('http://www.test.com').should be_true
end

it 'marks Unicode domain as valid (NOTE: works only with a scheme)' do
PostRank::URI.valid?('http://президент.рф').should be_true
end

it 'marks punycode domain domain as valid' do
PostRank::URI.valid?('xn--d1abbgf6aiiy.xn--p1ai').should be_true
end
end
end

0 comments on commit 2b93565

Please sign in to comment.