diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-03-17 15:35:38 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-03-17 15:35:38 +0000 |
commit | f626a17d8c8a2c2c0ce2c2a5cc1f3b6b1fc643c3 (patch) | |
tree | c8754e8516265ed0ed06d10f162c5109783b8dd1 /test | |
parent | 4067fd028dfdaeaa177755e5d2ff54511da8a7fc (diff) | |
download | ruby-f626a17d8c8a2c2c0ce2c2a5cc1f3b6b1fc643c3.tar.gz |
* lib/uri/common.rb (URI#{en,de}code_www_form_component):
renamed from URI#{en,de}code_www_component. [ruby-dev:40672]
* lib/uri/common.rb (URI#encode_www_form_component): %-encoded
element should have always two hex.
* lib/uri/common.rb (URI#encode_www_form_component):
better treatment for ASCII incompatible encodings and
encodings whose lead byte may use 7bit.
* lib/uri/common.rb (URI#decode_www_form_component): add %20.
* lib/uri/common.rb (URI#decode_www_form_component): add
result's encoding as 2nd argument.
* lib/uri/common.rb (URI#decode_www_form): added.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26962 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/uri/test_common.rb | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb index 9a5fd6751f..730210e8b3 100644 --- a/test/uri/test_common.rb +++ b/test/uri/test_common.rb @@ -50,16 +50,22 @@ class TestCommon < Test::Unit::TestCase assert_raise(NoMethodError) { Object.new.URI("http://www.ruby-lang.org/") } end - def test_encode_www_component - assert_equal("+%21%22%23%24%25%26%27%28%29*%2B%2C-.%2F09%3A%3B%3C%3D%3E%3F%40" \ + def test_encode_www_form_component + assert_equal("%00+%21%22%23%24%25%26%27%28%29*%2B%2C-.%2F09%3A%3B%3C%3D%3E%3F%40" \ "AZ%5B%5C%5D%5E_%60az%7B%7C%7D%7E", - URI.encode_www_component(" !\"\#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~")) + URI.encode_www_form_component("\x00 !\"\#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~")) + assert_equal("%95%41", URI.encode_www_form_component( + "\x95\x41".force_encoding(Encoding::Shift_JIS))) + assert_equal("%30%42", URI.encode_www_form_component( + "\x30\x42".force_encoding(Encoding::UTF_16BE))) + assert_equal("%30%42", URI.encode_www_form_component( + "\x30\x42".force_encoding(Encoding::ISO_2022_JP))) end - def test_decode_www_component - assert_equal(" !\"\#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~", - URI.decode_www_component( - "+%21%22%23%24%25%26%27%28%29*%2B%2C-.%2F09%3A%3B%3C%3D%3E%3F%40" \ + def test_decode_www_form_component + assert_equal(" !\"\#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~", + URI.decode_www_form_component( + "%20+%21%22%23%24%25%26%27%28%29*%2B%2C-.%2F09%3A%3B%3C%3D%3E%3F%40" \ "AZ%5B%5C%5D%5E_%60az%7B%7C%7D%7E")) end @@ -74,6 +80,12 @@ 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"]])) end + + def test_decode_www_form + assert_equal([%w[a 1], %w[a 2]], URI.decode_www_form("a=1&a=2")) + assert_equal([%w[a 1], ["\u3042", "\u6F22"]], + URI.decode_www_form("a=1&%E3%81%82=%E6%BC%A2")) + end end |