ruby / uri

URI is a module providing classes to handle Uniform Resource Identifiers
https://ruby.github.io/uri/
Other
85 stars 46 forks source link

Tilde should not be escaped as per RFC3986 #117

Closed y4m4p closed 2 months ago

y4m4p commented 3 months ago

Hi, first time contributing so sorry if I'm missing anything!

Issue

Heads up

This might be a breaking change, since some server-client setup might rely on ~ being encoded to %7E for whatever reason. But since this is an RFC offense, the proposed implementation should be the way to go and must be enforced for future usage in web interactive applications and such.

Decoding ~ must remain the same, we just don't want to encode ~.

Details

This PR's change follows other escaping methods in core Ruby, such as CGI.escape, ERB::Util.url_encode (which actually just calls CGI.escapeURIComponent inside).

# URI (current implementation)
irb(main):002:0> require 'uri'
=> true
irb(main):004:0> URI.encode_www_form_component("ruby~test")
=> "ruby%7Etest"

# CGI
irb(main):001:0> require 'cgi'
=> true
irb(main):003:0> CGI.escape("ruby~test")
=> "ruby~test"

# ERB
irb(main):009:0> require 'erb'
=> true
irb(main):012:0> ERB::Util.url_encode("ruby~test")
=> "ruby~test"

# Webrick
# needs webrick gem installed
[3] pry(main)> require 'webrick'
=> true
[4] pry(main)> WEBrick::HTTPUtils.escape_form("ruby~test")
=> "ruby~test"
[5] pry(main)> WEBrick::HTTPUtils.escape("ruby~test")
=> "ruby~test"
hsbt commented 2 months ago

I'm closing this by https://bugs.ruby-lang.org/issues/20690#note-2