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

ruby-changes:28768

From: naruse <ko1@a...>
Date: Sun, 19 May 2013 03:58:25 +0900 (JST)
Subject: [ruby-changes:28768] naruse:r40820 (trunk): * lib/uri/common.rb (URI.decode_www_form): scrub string if decoded

naruse	2013-05-19 03:58:13 +0900 (Sun, 19 May 2013)

  New Revision: 40820

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40820

  Log:
    * lib/uri/common.rb (URI.decode_www_form): scrub string if decoded
      bytes are invalid for the encoding.

  Modified files:
    trunk/ChangeLog
    trunk/lib/uri/common.rb
    trunk/test/uri/test_common.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40819)
+++ ChangeLog	(revision 40820)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun May 19 03:48:26 2013  NARUSE, Yui  <naruse@r...>
+
+	* lib/uri/common.rb (URI.decode_www_form): scrub string if decoded
+	  bytes are invalid for the encoding.
+
 Sun May 19 02:46:32 2013  Akinori MUSHA  <knu@i...>
 
 	* lib/set.rb (Set#delete_if, Set#keep_if): Make Set#delete_if and
Index: lib/uri/common.rb
===================================================================
--- lib/uri/common.rb	(revision 40819)
+++ lib/uri/common.rb	(revision 40820)
@@ -981,17 +981,9 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/common.rb#L981
         isindex = false
       end
 
-      if use__charset_
-        if key == '_charset_'
-          if e = get_encoding(val)
-            enc = e
-            use__charset_ = false
-            ary.each do |k, v|
-              v.force_encoding(enc)
-              k.force_encoding(enc)
-            end
-          end
-        end
+      if use__charset_ and key == '_charset_' and e = get_encoding(val)
+        enc = e
+        use__charset_ = false
       end
 
       key.gsub!(/\+|%\h\h/, TBLDECWWWCOMP_)
@@ -1001,10 +993,14 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/common.rb#L993
         val = ''
       end
 
-      val.force_encoding(enc)
-      key.force_encoding(enc)
       ary << [key, val]
     end
+    ary.each do |k, v|
+      k.force_encoding(enc)
+      k.scrub!
+      v.force_encoding(enc)
+      v.scrub!
+    end
     ary
   end
 
Index: test/uri/test_common.rb
===================================================================
--- test/uri/test_common.rb	(revision 40819)
+++ test/uri/test_common.rb	(revision 40820)
@@ -135,6 +135,8 @@ class TestCommon < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/uri/test_common.rb#L135
     assert_raise(ArgumentError){URI.decode_www_form("\u3042")}
     assert_equal([%w[a 1], ["\u3042", "\u6F22"]],
                  URI.decode_www_form("a=1&%E3%81%82=%E6%BC%A2"))
+    assert_equal([%w[a 1], ["\uFFFD%8", "\uFFFD"]],
+                 URI.decode_www_form("a=1&%E3%81%8=%E6%BC"))
     assert_equal([%w[?a 1], %w[a 2]], URI.decode_www_form("?a=1&a=2"))
     assert_equal([], URI.decode_www_form(""))
     assert_equal([%w[% 1]], URI.decode_www_form("%=1"))

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

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