[前][次][番号順一覧][スレッド一覧]

ruby-changes:46657

From: k0kubun <ko1@a...>
Date: Wed, 17 May 2017 21:35:08 +0900 (JST)
Subject: [ruby-changes:46657] k0kubun:r58773 (trunk): cgi/util.rb: Don't escape tilde in #escape

k0kubun	2017-05-17 21:34:59 +0900 (Wed, 17 May 2017)

  New Revision: 58773

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58773

  Log:
    cgi/util.rb: Don't escape tilde in #escape
    
    to make it compatible with ERB::Util.url_encode.
    
    ext/cgi/escape/escape.c: ditto.

  Modified files:
    trunk/ext/cgi/escape/escape.c
    trunk/lib/cgi/util.rb
    trunk/test/cgi/test_cgi_util.rb
Index: lib/cgi/util.rb
===================================================================
--- lib/cgi/util.rb	(revision 58772)
+++ lib/cgi/util.rb	(revision 58773)
@@ -11,7 +11,7 @@ module CGI::Util https://github.com/ruby/ruby/blob/trunk/lib/cgi/util.rb#L11
   #      # => "%27Stop%21%27+said+Fred"
   def escape(string)
     encoding = string.encoding
-    string.b.gsub(/([^ a-zA-Z0-9_.-]+)/) do |m|
+    string.b.gsub(/([^ a-zA-Z0-9_.\-~]+)/) do |m|
       '%' + m.unpack('H2' * m.bytesize).join('%').upcase
     end.tr(' ', '+').force_encoding(encoding)
   end
Index: test/cgi/test_cgi_util.rb
===================================================================
--- test/cgi/test_cgi_util.rb	(revision 58772)
+++ test/cgi/test_cgi_util.rb	(revision 58773)
@@ -29,6 +29,12 @@ class CGIUtilTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_util.rb#L29
     assert_equal('%26%3C%3E%22+%E3%82%86%E3%82%93%E3%82%86%E3%82%93'.ascii_only?, CGI::escape(@str1).ascii_only?) if defined?(::Encoding)
   end
 
+  def test_cgi_escape_with_unreserved_characters
+      assert_equal("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",
+		 CGI::escape("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"),
+                 "should not escape any unreserved characters, as per RFC3986 Section 2.3")
+  end
+
   def test_cgi_escape_with_invalid_byte_sequence
     assert_nothing_raised(ArgumentError) do
       assert_equal('%C0%3C%3C', CGI::escape("\xC0\<\<".dup.force_encoding("UTF-8")))
Index: ext/cgi/escape/escape.c
===================================================================
--- ext/cgi/escape/escape.c	(revision 58772)
+++ ext/cgi/escape/escape.c	(revision 58773)
@@ -196,7 +196,7 @@ url_unreserved_char(unsigned char c) https://github.com/ruby/ruby/blob/trunk/ext/cgi/escape/escape.c#L196
       case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J':
       case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T':
       case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
-      case '-': case '.': case '_':
+      case '-': case '.': case '_': case '~':
         return 1;
       default:
         break;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]