-
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
JRuby compatibility (drop libidn requirement) #66
Comments
It is possible (See platform in http://bundler.io/man/gemfile.5.html)
Agree, we'd like the same behaviour under JRuby and Ruby. |
#63 fixed #48 which was about sporkmonger/addressable#215, which now has been fixed in sporkmonger/addressable@cf8cc7d and released in Addressable 2.4.0. |
Yes: https://github.com/sporkmonger/addressable/blob/addressable-2.4.0/Gemfile#L27 |
Tried Adressable 2.4.0 without $ git d
diff --git a/lib/twingly/url.rb b/lib/twingly/url.rb
index 282e13a..499579e 100644
--- a/lib/twingly/url.rb
+++ b/lib/twingly/url.rb
@@ -1,5 +1,4 @@
require "addressable/uri"
-require "addressable/idna/native"
require "public_suffix"
require_relative "url/null_url"
@@ -16,7 +15,7 @@ module Twingly
ERRORS = [
Addressable::URI::InvalidURIError,
PublicSuffix::DomainInvalid,
- IDN::Idna::IdnaError,
+ Addressable::IDNA::PunycodeBadInput,
]
def self.parse(potential_url)
diff --git a/twingly-url.gemspec b/twingly-url.gemspec
index 915e5d2..b8be843 100644
--- a/twingly-url.gemspec
+++ b/twingly-url.gemspec
@@ -12,9 +12,8 @@ Gem::Specification.new do |s|
s.license = "MIT"
s.required_ruby_version = "~> 2.2"
- s.add_dependency "addressable", "~> 2"
+ s.add_dependency "addressable", "~> 2.4"
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" Two failures (about the same URL)
|
# with idn-ruby
[6] pry(main)> Addressable::URI.parse("http://xn--zckp1cyg1.sblo.jp/").display_uri
=> #<Addressable::URI:0x3ff9cf027390 URI:http://xn--zckp1cyg1.sblo.jp/>
# without
[6] pry(main)> Addressable::URI.parse("http://xn--zckp1cyg1.sblo.jp/").display_uri
Addressable::IDNA::PunycodeBadInput: Input is invalid.
from /Users/dentarg/.gem/ruby/2.2.3/gems/addressable-2.4.0/lib/addressable/idna/pure.rb:562:in `punycode_decode' |
Is http://xn--zckp1cyg1.sblo.jp/ valid? :) |
It's resolvable at least:
|
Yes, but someone might have registered a "faulty" sub-domain. I tried some different online tools and they all had troubles converting it. |
But even so, we should of course not blow up. |
@walro If you want to you can weigh in at sporkmonger/addressable#219 |
@walro what tools did you try? sounds like we can change our spec then, if we revert the use of libidn |
https://www.punycoder.com/ and http://www.charset.org/punycode.php?encoded=xn--zckp1cyg1&decode=Punycode+to+normal+text The latter does infact handle most part of it, but I suspect that the "box" at the end implicates an error. However, I think our library should just treat it as a normal string that just happens to start with xn--, rather than blowing up so I don't see us reverting the use of libidn just yet. |
I played around with the CLI for libidn (from Homebrew)
Something valid:
|
Played around some more
|
Ah
|
Has been solved (sporkmonger/addressable@295d7ba) but not yet released. |
Summary: with the fix in addressable we would be able to handle #48 without libidn |
Hmm, this is tricky... :| We have seen URLs like
Without [1] pry(main)> Twingly::URL.parse("http://AcinusFallumTrompetumNullunCreditumVisumEstAtCuadLongumEtCefallumEst.com")
=> #<Twingly::URL:0x3fc872208c4c http://AcinusFallumTrompetumNullunCreditumVisumEstAtCuadLongumEtCefallumEst.com> With [1] pry(main)> Twingly::URL.parse("http://AcinusFallumTrompetumNullunCreditumVisumEstAtCuadLongumEtCefallumEst.com")
=> #<Twingly::URL::NullURL:0x007fe54b31c378> this is the error [4] pry(main)> Addressable::URI.heuristic_parse("http://AcinusFallumTrompetumNullunCreditumVisumEstAtCuadLongumEtCefallumEst.com").normalized_host
IDN::Idna::IdnaError: Output would be too large or too small (5)
from /Users/dentarg/.gem/ruby/2.2.5/gems/addressable-2.4.0/lib/addressable/idna/native.rb:38:in `toASCII' no
|
I'd guess libidn conforms to the maxlength of 63, http://stackoverflow.com/questions/14402407/maximum-length-of-a-domain-name-without-the-http-www-com-parts |
I guess the consequence would be that we will see more [3] pry(main)> Net::HTTP.get(URI("http://AcinusFallumTrompetumNullunCreditumVisumEstAtCuadLongumEtCefallumEst.com"))
SocketError: getaddrinfo: nodename nor servname provided, or not known
from /Users/dentarg/.rubies/ruby-2.2.5/lib/ruby/2.2.0/net/http.rb:879:in `initialize' |
Currently, this URL isn't valid, but if we drop libidn (which we talked about), it would be valid, due to the way Addressable 2.4.0 works. See comment at: #66 (comment) Adding this URL to the tests so we will notice the change in behaviour, if/when we drop libidn.
I reported the above mentioned difference in behaviour to addressable: sporkmonger/addressable#239 |
Instead, we use the pure Ruby IDNA solution in addressable. Close #66.
And it was fixed in sporkmonger/addressable@c73810f |
Since the introduction of the
idn-ruby
gem in #63 we can no longer run under the Java runtime. Some ideas from the top of my head:idn-ruby
for Java platform.The text was updated successfully, but these errors were encountered: