ruby-changes:46656
From: k0kubun <ko1@a...>
Date: Wed, 17 May 2017 20:58:17 +0900 (JST)
Subject: [ruby-changes:46656] k0kubun:r58772 (trunk): erb.rb: Don't encode tilde in #url_encode
k0kubun 2017-05-17 20:58:09 +0900 (Wed, 17 May 2017) New Revision: 58772 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58772 Log: erb.rb: Don't encode tilde in #url_encode Based on patch by madeofcode (Mark Dodwell). [ruby-core:46168] [Bug #6696] [Fix GH-54] `~` is a unreserved character. https://tools.ietf.org/html/rfc3986#section-2.3 Modified files: trunk/lib/erb.rb trunk/test/erb/test_erb.rb Index: lib/erb.rb =================================================================== --- lib/erb.rb (revision 58771) +++ lib/erb.rb (revision 58772) @@ -994,7 +994,7 @@ class ERB https://github.com/ruby/ruby/blob/trunk/lib/erb.rb#L994 # Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide # def url_encode(s) - s.to_s.b.gsub(/[^a-zA-Z0-9_\-.]/n) { |m| + s.to_s.b.gsub(/[^a-zA-Z0-9_\-.~]/n) { |m| sprintf("%%%02X", m.unpack("C")[0]) } end Index: test/erb/test_erb.rb =================================================================== --- test/erb/test_erb.rb (revision 58771) +++ test/erb/test_erb.rb (revision 58772) @@ -464,6 +464,10 @@ EOS https://github.com/ruby/ruby/blob/trunk/test/erb/test_erb.rb#L464 assert_equal("%A5%B5%A5%F3%A5%D7%A5%EB", ERB::Util.url_encode("\xA5\xB5\xA5\xF3\xA5\xD7\xA5\xEB".force_encoding("EUC-JP"))) + + assert_equal("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~", + ERB::Util.url_encode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"), + "should not escape any unreserved characters, as per RFC3986 Section 2.3") end def test_percent_after_etag -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/