mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
652ab6d3a5
commit
c4087bcb12
3 changed files with 36 additions and 18 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
end
|
||||
str << encode_www_form_component(k)
|
||||
enum.map do |k,v|
|
||||
str = encode_www_form_component(k)
|
||||
if v
|
||||
str << '='
|
||||
str << encode_www_form_component(v)
|
||||
end
|
||||
str
|
||||
end.join('&')
|
||||
end
|
||||
|
||||
WFKV_ = '(?:%\h\h|[^%#=;&]+)' # :nodoc:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue