зеркало из https://github.com/github/ruby.git
* test/cgi: check by Encoding.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26154 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
da861d79b7
Коммит
738515d12b
|
@ -9,7 +9,7 @@ class CGICookieTest < Test::Unit::TestCase
|
|||
def setup
|
||||
ENV['REQUEST_METHOD'] = 'GET'
|
||||
@str1="\xE3\x82\x86\xE3\x82\x93\xE3\x82\x86\xE3\x82\x93"
|
||||
@str1.force_encoding("UTF-8") if RUBY_VERSION>="1.9"
|
||||
@str1.force_encoding("UTF-8") if defined?(::Encoding)
|
||||
end
|
||||
|
||||
def teardown
|
||||
|
@ -34,7 +34,7 @@ class CGICookieTest < Test::Unit::TestCase
|
|||
def test_cgi_cookie_new_complex
|
||||
t = Time.gm(2030, 12, 31, 23, 59, 59)
|
||||
value = ['val1', '&<>"', "\xA5\xE0\xA5\xB9\xA5\xAB"]
|
||||
value[2].force_encoding("EUC-JP") if RUBY_VERSION>="1.9"
|
||||
value[2].force_encoding("EUC-JP") if defined?(::Encoding)
|
||||
cookie = CGI::Cookie.new('name'=>'name1',
|
||||
'value'=>value,
|
||||
'path'=>'/cgi-bin/myapp/',
|
||||
|
|
|
@ -124,7 +124,7 @@ class CGICoreTest < Test::Unit::TestCase
|
|||
$stdin = StringIO.new
|
||||
$stdin << query_str
|
||||
$stdin.rewind
|
||||
if RUBY_VERSION>="1.9.0"
|
||||
if defined?(::Encoding)
|
||||
hash={}
|
||||
cgi = CGI.new(:accept_charset=>"UTF-8"){|key,val|hash[key]=val}
|
||||
## cgi[]
|
||||
|
@ -251,7 +251,7 @@ class CGICoreTest < Test::Unit::TestCase
|
|||
"Content-Length: 22\r\n" +
|
||||
"\r\n" +
|
||||
euc_str
|
||||
if RUBY_VERSION>="1.9"
|
||||
if defined?(::Encoding)
|
||||
actual.force_encoding("ASCII-8BIT")
|
||||
expected.force_encoding("ASCII-8BIT")
|
||||
end
|
||||
|
|
|
@ -32,7 +32,7 @@ class MultiPart
|
|||
def initialize(boundary=nil)
|
||||
@boundary = boundary || create_boundary()
|
||||
@buf = ''
|
||||
@buf.force_encoding("ascii-8bit") if RUBY_VERSION>="1.9"
|
||||
@buf.force_encoding(::Encoding::ASCII_8BIT) if defined?(::Encoding)
|
||||
end
|
||||
attr_reader :boundary
|
||||
|
||||
|
@ -44,11 +44,8 @@ class MultiPart
|
|||
buf << "Content-Disposition: form-data: name=\"#{name}\"#{s}\r\n"
|
||||
buf << "Content-Type: #{content_type}\r\n" if content_type
|
||||
buf << "\r\n"
|
||||
if RUBY_VERSION>="1.9"
|
||||
buf << value.dup.force_encoding("ASCII-8BIT")
|
||||
else
|
||||
value = value.dup.force_encoding(::Encoding::ASCII_8BIT) if defined?(::Encoding)
|
||||
buf << value
|
||||
end
|
||||
buf << "\r\n"
|
||||
return self
|
||||
end
|
||||
|
@ -192,7 +189,7 @@ class CGIMultipartTest < Test::Unit::TestCase
|
|||
{:name=>'image1', :value=>_read('small.png'),
|
||||
:filename=>'small.png', :content_type=>'image/png'}, # small image
|
||||
]
|
||||
@data[1][:value].force_encoding("UTF-8") if RUBY_VERSION>="1.9"
|
||||
@data[1][:value].force_encoding(::Encoding::UTF_8) if defined?(::Encoding)
|
||||
@expected_class = StringIO
|
||||
_test_multipart()
|
||||
end
|
||||
|
@ -208,7 +205,7 @@ class CGIMultipartTest < Test::Unit::TestCase
|
|||
{:name=>'image1', :value=>_read('large.png'),
|
||||
:filename=>'large.png', :content_type=>'image/png'}, # large image
|
||||
]
|
||||
@data[1][:value].force_encoding("UTF-8") if RUBY_VERSION>="1.9"
|
||||
@data[1][:value].force_encoding(::Encoding::UTF_8) if defined?(::Encoding)
|
||||
@expected_class = Tempfile
|
||||
_test_multipart()
|
||||
end
|
||||
|
|
|
@ -27,7 +27,7 @@ class CGISessionTest < Test::Unit::TestCase
|
|||
}
|
||||
value1="value1"
|
||||
value2="\x8F\xBC\x8D]"
|
||||
value2.force_encoding("SJIS") if RUBY_VERSION>="1.9"
|
||||
value2.force_encoding("SJIS") if defined?(::Encoding)
|
||||
ENV.update(@environ)
|
||||
cgi = CGI.new
|
||||
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir)
|
||||
|
@ -65,7 +65,7 @@ class CGISessionTest < Test::Unit::TestCase
|
|||
}
|
||||
value1="value1"
|
||||
value2="\x8F\xBC\x8D]"
|
||||
value2.force_encoding("SJIS") if RUBY_VERSION>="1.9"
|
||||
value2.force_encoding("SJIS") if defined?(::Encoding)
|
||||
ENV.update(@environ)
|
||||
cgi = CGI.new
|
||||
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"database_manager"=>CGI::Session::PStore)
|
||||
|
@ -102,7 +102,7 @@ class CGISessionTest < Test::Unit::TestCase
|
|||
}
|
||||
value1="value1"
|
||||
value2="\x8F\xBC\x8D]"
|
||||
value2.force_encoding("SJIS") if RUBY_VERSION>="1.9"
|
||||
value2.force_encoding("SJIS") if defined?(::Encoding)
|
||||
ENV.update(@environ)
|
||||
cgi = CGI.new
|
||||
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"session_id"=>"foo")
|
||||
|
@ -142,7 +142,7 @@ class CGISessionTest < Test::Unit::TestCase
|
|||
}
|
||||
value1="value1"
|
||||
value2="\x8F\xBC\x8D]"
|
||||
value2.force_encoding("SJIS") if RUBY_VERSION>="1.9"
|
||||
value2.force_encoding("SJIS") if defined?(::Encoding)
|
||||
ENV.update(@environ)
|
||||
cgi = CGI.new
|
||||
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"session_key"=>"bar")
|
||||
|
|
|
@ -9,7 +9,7 @@ class CGIUtilTest < Test::Unit::TestCase
|
|||
def setup
|
||||
ENV['REQUEST_METHOD'] = 'GET'
|
||||
@str1="&<>\" \xE3\x82\x86\xE3\x82\x93\xE3\x82\x86\xE3\x82\x93"
|
||||
@str1.force_encoding("UTF-8") if RUBY_VERSION>="1.9"
|
||||
@str1.force_encoding("UTF-8") if defined?(::Encoding)
|
||||
end
|
||||
|
||||
def teardown
|
||||
|
@ -21,12 +21,12 @@ class CGIUtilTest < Test::Unit::TestCase
|
|||
|
||||
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))
|
||||
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 RUBY_VERSION>="1.9"
|
||||
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)
|
||||
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'))
|
||||
assert_equal(@str1.encoding, CGI::unescape('%26%3C%3E%22+%E3%82%86%E3%82%93%E3%82%86%E3%82%93').encoding) if RUBY_VERSION>="1.9"
|
||||
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)
|
||||
end
|
||||
|
||||
def test_cgi_pretty
|
||||
|
|
Загрузка…
Ссылка в новой задаче