2009-07-30 01:34:02 -04:00
|
|
|
require 'test/unit'
|
|
|
|
require 'cgi'
|
|
|
|
require 'stringio'
|
|
|
|
|
|
|
|
|
|
|
|
class CGIUtilTest < Test::Unit::TestCase
|
|
|
|
|
|
|
|
|
|
|
|
def setup
|
|
|
|
ENV['REQUEST_METHOD'] = 'GET'
|
|
|
|
@str1="&<>\" \xE3\x82\x86\xE3\x82\x93\xE3\x82\x86\xE3\x82\x93"
|
2009-12-22 19:14:48 -05:00
|
|
|
@str1.force_encoding("UTF-8") if defined?(::Encoding)
|
2009-07-30 01:34:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
%W[REQUEST_METHOD SCRIPT_NAME].each do |name|
|
|
|
|
ENV.delete(name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def test_cgi_escape
|
|
|
|
assert_equal('%26%3C%3E%22+%E3%82%86%E3%82%93%E3%82%86%E3%82%93', CGI::escape(@str1))
|
2009-12-22 19:14:48 -05:00
|
|
|
assert_equal('%26%3C%3E%22+%E3%82%86%E3%82%93%E3%82%86%E3%82%93'.ascii_only?, CGI::escape(@str1).ascii_only?) if defined?(::Encoding)
|
2009-07-30 01:34:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_cgi_unescape
|
|
|
|
assert_equal(@str1, CGI::unescape('%26%3C%3E%22+%E3%82%86%E3%82%93%E3%82%86%E3%82%93'))
|
2009-12-22 19:14:48 -05:00
|
|
|
assert_equal(@str1.encoding, CGI::unescape('%26%3C%3E%22+%E3%82%86%E3%82%93%E3%82%86%E3%82%93').encoding) if defined?(::Encoding)
|
2010-10-13 09:39:13 -04:00
|
|
|
assert_equal("\u{30E1 30E2 30EA 691C 7D22}", CGI.unescape("\u{30E1 30E2 30EA}%E6%A4%9C%E7%B4%A2"))
|
2009-07-30 01:34:02 -04:00
|
|
|
end
|
|
|
|
|
2009-07-30 03:39:09 -04:00
|
|
|
def test_cgi_pretty
|
|
|
|
assert_equal("<HTML>\n <BODY>\n </BODY>\n</HTML>\n",CGI::pretty("<HTML><BODY></BODY></HTML>"))
|
|
|
|
assert_equal("<HTML>\n\t<BODY>\n\t</BODY>\n</HTML>\n",CGI::pretty("<HTML><BODY></BODY></HTML>","\t"))
|
|
|
|
end
|
|
|
|
|
2009-07-30 01:34:02 -04:00
|
|
|
end
|