diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/uri/common.rb | 22 | ||||
-rw-r--r-- | test/uri/test_common.rb | 2 |
3 files changed, 16 insertions, 13 deletions
@@ -1,3 +1,8 @@ +Sun May 19 03:48:26 2013 NARUSE, Yui <naruse@ruby-lang.org> + + * 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@iDaemons.org> * lib/set.rb (Set#delete_if, Set#keep_if): Make Set#delete_if and diff --git a/lib/uri/common.rb b/lib/uri/common.rb index 5914868e94..1da9f47647 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -981,17 +981,9 @@ module URI 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 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 diff --git a/test/uri/test_common.rb b/test/uri/test_common.rb index a72d7bf9be..65a92f3868 100644 --- a/test/uri/test_common.rb +++ b/test/uri/test_common.rb @@ -135,6 +135,8 @@ class TestCommon < Test::Unit::TestCase 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")) |