aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog19
-rw-r--r--lib/uri/common.rb20
-rw-r--r--test/uri/test_common.rb15
3 files changed, 36 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index e9cd6782b3..aa89caf350 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Thu Sep 30 09:29:06 2010 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* vm_dump.c (dump_thread): fixed wrong type of return value of
@@ -74,10 +81,10 @@ Mon Sep 27 23:30:34 2010 Koichi Sasada <ko1@atdot.net>
Mon Sep 27 15:54:03 2010 URABE Shyouhei <shyouhei@ruby-lang.org>
* 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@ruby-lang.org>
@@ -258,7 +265,7 @@ Sun Sep 19 20:37:45 2010 Yuki Sonoda (Yugui) <yugui@yugui.jp>
* 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@ruby-lang.org>
@@ -734,7 +741,7 @@ Sat Sep 4 10:40:50 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
Sun May 23 17:29:41 2010 Yuki Sonoda (Yugui) <yugui@yugui.jp>
- * 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@yugui.jp>
diff --git a/lib/uri/common.rb b/lib/uri/common.rb
index 3f92423b1a..e6f189bdbe 100644
--- a/lib/uri/common.rb
+++ b/lib/uri/common.rb
@@ -346,7 +346,7 @@ module URI
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 @@ module URI
#
# 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:
diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb
index 01381b20e6..410f46bd0b 100644
--- a/test/uri/test_common.rb
+++ b/test/uri/test_common.rb
@@ -82,6 +82,21 @@ class TestCommon < Test::Unit::TestCase
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