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

ruby-changes:17371

From: naruse <ko1@a...>
Date: Thu, 30 Sep 2010 09:48:07 +0900 (JST)
Subject: [ruby-changes:17371] Ruby:r29376 (trunk): * lib/uri/common.rb (URI.encode_www_form): change treatment of

naruse	2010-09-30 09:48:01 +0900 (Thu, 30 Sep 2010)

  New Revision: 29376

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

  Log:
    * lib/uri/common.rb (URI.encode_www_form): change treatment of
      undefined value in given array as latest internet draft for
      application/www-form-urlencoded.
      http://tools.ietf.org/html/draft-hoehrmann-urlencoded-01

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 29375)
+++ ChangeLog	(revision 29376)
@@ -1,3 +1,10 @@
+Thu Sep 30 09:29:06 2010  NARUSE, Yui  <naruse@r...>
+
+	* lib/uri/common.rb (URI.encode_www_form): change treatment of
+	  undefined value in given array as latest internet draft for
+	  application/www-form-urlencoded.
+	  http://tools.ietf.org/html/draft-hoehrmann-urlencoded-01
+
 Thu Sep 30 09:34:03 2010  NAKAMURA Usaku  <usa@r...>
 
 	* vm_dump.c (dump_thread): fixed wrong type of return value of
@@ -74,10 +81,10 @@
 Mon Sep 27 15:54:03 2010  URABE Shyouhei  <shyouhei@r...>
 
 	* test/net/http/test_https.rb: As always, localhost is not
-          guaranteed to be resolved as 127.0.0.1.  But a SSL
-          certificate needs a socket to listen on a specific address
-          where a CN resolves to.  On situations where localhost is
-          not 127.0.0.1, these tests are not possible.
+	  guaranteed to be resolved as 127.0.0.1.  But a SSL
+	  certificate needs a socket to listen on a specific address
+	  where a CN resolves to.  On situations where localhost is
+	  not 127.0.0.1, these tests are not possible.
 
 Mon Sep 27 15:25:05 2010  URABE Shyouhei  <shyouhei@r...>
 
@@ -258,7 +265,7 @@
 
 	* Makefile.in (clean-capi, distclean-capi, realclean-capi): ditto.
 
-	* win32/Makefile.sub (clean-capi, distclean-capi, realclean-capi): 
+	* win32/Makefile.sub (clean-capi, distclean-capi, realclean-capi):
 	  ditto.
 
 Sun Sep 19 13:44:24 2010  Nobuyoshi Nakada  <nobu@r...>
@@ -734,7 +741,7 @@
 
 Sun May 23 17:29:41 2010  Yuki Sonoda (Yugui)  <yugui@y...>
 
-	* common.mk (capi): uses a timestamp file to get rid of 
+	* common.mk (capi): uses a timestamp file to get rid of
 	  generating twice.
 
 Fri Jun 18 01:33:21 2010  Yuki Sonoda (Yugui)  <yugui@y...>
Index: lib/uri/common.rb
===================================================================
--- lib/uri/common.rb	(revision 29375)
+++ lib/uri/common.rb	(revision 29376)
@@ -346,7 +346,7 @@
       ret[:REL_URI] = rel_uri = "(?:#{net_path}|#{abs_path}|#{rel_path})(?:\\?#{query})?"
 
       # URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
-      ret[:URI_REF] = uri_ref = "(?:#{abs_uri}|#{rel_uri})?(?:##{fragment})?"
+      ret[:URI_REF] = "(?:#{abs_uri}|#{rel_uri})?(?:##{fragment})?"
 
       ret[:X_ABS_URI] = "
         (#{scheme}):                           (?# 1: scheme)
@@ -797,18 +797,14 @@
   #
   # See URI.encode_www_form_component, URI.decode_www_form
   def self.encode_www_form(enum)
-    str = nil
-    enum.each do |k,v|
-      if str
-        str << '&'
-      else
-        str = nil.to_s
+    enum.map do |k,v|
+      str = encode_www_form_component(k)
+      if v
+        str << '='
+        str << encode_www_form_component(v)
       end
-      str << encode_www_form_component(k)
-      str << '='
-      str << encode_www_form_component(v)
-    end
-    str
+      str
+    end.join('&')
   end
 
   WFKV_ = '(?:%\h\h|[^%#=;&]+)' # :nodoc:
Index: test/uri/test_common.rb
===================================================================
--- test/uri/test_common.rb	(revision 29375)
+++ test/uri/test_common.rb	(revision 29376)
@@ -82,6 +82,21 @@
     assert_equal(expected, URI.encode_www_form(a: 1, :"\u3042" => "\u6F22"))
     assert_equal(expected, URI.encode_www_form([["a", "1"], ["\u3042", "\u6F22"]]))
     assert_equal(expected, URI.encode_www_form([[:a, 1], [:"\u3042", "\u6F22"]]))
+
+    assert_equal('+a+=+1+', URI.encode_www_form([[' a ', ' 1 ']]))
+    assert_equal('text=x%0Ay', URI.encode_www_form([['text', "x\u000Ay"]]))
+    assert_equal('constellation=Bo%C3%B6tes', URI.encode_www_form([['constellation', "Bo\u00F6tes"]]))
+    assert_equal('name=%00value', URI.encode_www_form([['name', "\u0000value"]]))
+    assert_equal('Cipher=c%3D%28m%5Ee%29%25n', URI.encode_www_form([['Cipher', 'c=(m^e)%n']]))
+    assert_equal('&', URI.encode_www_form([['', nil], ['', nil]]))
+    assert_equal('&=', URI.encode_www_form([['', nil], ['', '']]))
+    assert_equal('=&', URI.encode_www_form([['', ''], ['', nil]]))
+    assert_equal('=&=', URI.encode_www_form([['', ''], ['', '']]))
+    assert_equal('', URI.encode_www_form([['', nil]]))
+    assert_equal('', URI.encode_www_form([]))
+    assert_equal('=', URI.encode_www_form([['', '']]))
+    assert_equal('a%26b=1&c=2%3B3&e=4', URI.encode_www_form([['a&b', '1'], ['c', '2;3'], ['e', '4']]))
+    assert_equal('image&title&price', URI.encode_www_form([['image', nil], ['title', nil], ['price', nil]]))
   end
 
   def test_decode_www_form

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

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