-
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
Same URL in Unicode isn't equal to the same ASCII URL #94
Comments
Yes, we need to normalize internally. |
$ bundle console
[1] pry(main)> u1 = Twingly::URL.parse("https://www.foo.ایران.ir/bar")
=> #<Twingly::URL:0x3fd236143104 https://www.foo.ایران.ir/bar>
[2] pry(main)> u2 = Twingly::URL.parse("https://www.foo.xn--mgba3a4f16a.ir/bar")
=> #<Twingly::URL:0x3fd2351830e8 https://www.foo.xn--mgba3a4f16a.ir/bar>
[3] pry(main)> u1 == u2
=> false |
@dentarg we use Comparable, so this affects a few generated methods, and all will be fixed when
|
We should also look over Hash Equality $ irb
irb(main):001:0> require 'twingly/url'
=> true
irb(main):002:0> Twingly::URL::VERSION
=> "5.0.1"
irb(main):003:0> url = 'http://google.com'
=> "http://google.com"
irb(main):004:0> url1 = url2 = Twingly::URL.parse(url)
=> #<Twingly::URL:0x3fe0c1959fac http://google.com>
irb(main):005:0> { url1 => 'url1' }.has_key?(url2)
=> true |
Oops, should not have done irb(main):009:0> url2 = Twingly::URL.parse(url)
=> #<Twingly::URL:0x3fe0c1910898 http://google.com>
irb(main):010:0> { url1 => 'url1' }.has_key?(url2)
=> false
irb(main):011:0> { url1 => 'url1' }.keys.include?(url2)
=> true |
Dumping related/interesting links: https://bugs.ruby-lang.org/issues/12852, https://url.spec.whatwg.org/ |
I think this was implemented in #129 $ bundle exec pry
[1] pry(main)> require_relative "lib/twingly/url"
=> true
[2] pry(main)> url = 'http://google.com'
=> "http://google.com"
[3] pry(main)> url1 = Twingly::URL.parse(url)
=> #<Twingly::URL:0x3fc3b6db63ac http://google.com>
[4] pry(main)> url2 = Twingly::URL.parse(url)
=> #<Twingly::URL:0x3fc3b6d939b0 http://google.com>
[5] pry(main)> { url1 => 'url1' }.has_key?(url2)
=> true
[6] pry(main)> { url1 => 'url1' }.keys.include?(url2)
=> true |
This is the case since we compare with
to_s
(code).We might also consider using the normalized version when comparing (might not be what we want though).
The text was updated successfully, but these errors were encountered: