-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not blow up on broken punycode URLs #48
Comments
Notes
[25] pry(main)> Addressable::URI.heuristic_parse("http://xn--...-/")
=> #<Addressable::URI:0x3fca3d522eec URI:http://xn--...-/>
[21] pry(main)> Addressable::URI.heuristic_parse("http://xn--...-/").display_uri
NoMethodError: undefined method `size' for nil:NilClass
from /Users/dentarg/.gem/ruby/2.2.3/gems/addressable-2.3.8/lib/addressable/idna/pure.rb:506:in `punycode_decode'
[23] pry(main)> Addressable::URI.heuristic_parse("http://xn--t...-/")
=> #<Addressable::URI:0x3fca3d53ae48 URI:http://xn--t...-/>
[22] pry(main)> Addressable::URI.heuristic_parse("http://xn--t...-/").display_uri
Addressable::IDNA::PunycodeBadInput: Input is invalid.
from /Users/dentarg/.gem/ruby/2.2.3/gems/addressable-2.3.8/lib/addressable/idna/pure.rb:563:in `punycode_decode' [27] pry(main)> Addressable::URI.heuristic_parse("http://xn--...-/").normalize.host
=> "xn--...-"
[28] pry(main)> Addressable::URI.heuristic_parse("http://xn--t...-/").normalize.host
=> "xn--t...-" [32] pry(main)> Addressable::IDNA.to_unicode("xn--...-")
NoMethodError: undefined method `size' for nil:NilClass
from /Users/dentarg/.gem/ruby/2.2.3/gems/addressable-2.3.8/lib/addressable/idna/pure.rb:506:in `punycode_decode'
[33] pry(main)> Addressable::IDNA.to_unicode("xn--t...-")
Addressable::IDNA::PunycodeBadInput: Input is invalid.
from /Users/dentarg/.gem/ruby/2.2.3/gems/addressable-2.3.8/lib/addressable/idna/pure.rb:563:in `punycode_decode'
|
For this one I suggest that we rescue |
Alternative solution From https://github.com/sporkmonger/addressable#install
[1] pry(main)> require "addressable/idna/native"
=> false
[2] pry(main)> Addressable::IDNA.to_unicode("xn--...-")
=> "xn--...-"
[3] pry(main)> Addressable::IDNA.to_unicode("xn--t...-")
=> "xn--t...-"
[4] pry(main)> Addressable::URI.heuristic_parse("http://xn--t...-/").display_uri
=> #<Addressable::URI:0x3fd6c24adaac URI:http://xn--t...-/>
[5] pry(main)> Addressable::URI.heuristic_parse("http://xn--t...-/").display_uri.host
=> "xn--t...-"
[6] pry(main)> Addressable::URI.heuristic_parse("http://xn--...-/").display_uri.host
=> "xn--...-" The specs pass with this diff diff --git a/twingly-url.gemspec b/twingly-url.gemspec
index 326fdaa..cbe1c12 100644
--- a/twingly-url.gemspec
+++ b/twingly-url.gemspec
@@ -14,6 +14,7 @@ Gem::Specification.new do |s|
s.add_dependency "addressable", "~> 2"
s.add_dependency "public_suffix", "~> 1.4"
+ s.add_dependency "idn-ruby", "~> 0.1"
s.add_development_dependency "rake", "~> 10"
s.add_development_dependency "rspec", "~> 3" |
Reported upstream: sporkmonger/addressable#215 |
Heroku has libidn11 and libidn11-dev: https://devcenter.heroku.com/articles/cedar-ubuntu-packages |
https://github.com/deepfryed/idn-ruby nothing new since 2011, but maybe that's not a problem |
Using libidn11 is not great for potential JRuby support, but I'm sure Java has something similar that could be used. |
|
It blew up for me on: |
This sounds like a good idea |
Those are not the same as "idn", maybe it works anyway. idn depends upon libidn11. So I think we need to make a test. |
The broken URLs
The failures
pushed an temporary branch with the specs, https://github.com/twingly/twingly-url/tree/tmp/issue/48
The text was updated successfully, but these errors were encountered: