diff options
author | xibbar <xibbar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-24 14:27:53 +0000 |
---|---|---|
committer | xibbar <xibbar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-24 14:27:53 +0000 |
commit | 3c419de10b113aceea7db10eb0d4521086696bc9 (patch) | |
tree | fa0766740eb668f1f6fb9d26136b5736afd587f4 /test/cgi | |
parent | 00e9e27b69c7af6fab649c789c6698d256982046 (diff) |
* lib/cgi/core.rb (CGI::new, CGI::{accept_charset,accept_charset=}) :
accept parameters either in a hash,
string as a block. add the encoding validation process.
* test/cgi/test_cgi_core.rb : test for query encoding check.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19530 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/cgi')
-rwxr-xr-x | test/cgi/test_cgi_core.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/cgi/test_cgi_core.rb b/test/cgi/test_cgi_core.rb index 6f420199d3..1298ae792d 100755 --- a/test/cgi/test_cgi_core.rb +++ b/test/cgi/test_cgi_core.rb @@ -99,6 +99,44 @@ class CGICoreTest < Test::Unit::TestCase assert_equal([], cgi.params['*notfound*']) end + def test_cgi_core_params_encoding_check + query_str = 'str=%BE%BE%B9%BE' + @environ = { + 'REQUEST_METHOD' => 'POST', + 'CONTENT_LENGTH' => query_str.length.to_s, + 'SERVER_SOFTWARE' => 'Apache 2.2.0', + 'SERVER_PROTOCOL' => 'HTTP/1.1', + } + ENV.update(@environ) + $stdin = StringIO.new + $stdin << query_str + $stdin.rewind + if RUBY_VERSION>="1.9.0" + hash={} + cgi = CGI.new(:accept_charset=>"UTF-8"){|key,val|hash[key]=val} + ## cgi[] + assert_equal("\xBE\xBE\xB9\xBE".force_encoding("ASCII-8BIT"), cgi['str']) + ## cgi.params + assert_equal(["\xBE\xBE\xB9\xBE".force_encoding("ASCII-8BIT")], cgi.params['str']) + ## accept-charset error + assert_equal({"str"=>"\xBE\xBE\xB9\xBE".force_encoding("ASCII-8BIT")},hash) + + $stdin.rewind + assert_raises(CGI::InvalidEncoding) do + cgi = CGI.new(:accept_charset=>"UTF-8") + end + + $stdin.rewind + cgi = CGI.new(:accept_charset=>"EUC-JP") + ## cgi[] + assert_equal("\xBE\xBE\xB9\xBE".force_encoding("EUC-JP"), cgi['str']) + ## cgi.params + assert_equal(["\xBE\xBE\xB9\xBE".force_encoding("EUC-JP")], cgi.params['str']) + else + assert(true) + end + end + def test_cgi_core_cookie @environ = { |