зеркало из 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
|
def setup
|
||||||
ENV['REQUEST_METHOD'] = 'GET'
|
ENV['REQUEST_METHOD'] = 'GET'
|
||||||
@str1="\xE3\x82\x86\xE3\x82\x93\xE3\x82\x86\xE3\x82\x93"
|
@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
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
|
@ -34,7 +34,7 @@ class CGICookieTest < Test::Unit::TestCase
|
||||||
def test_cgi_cookie_new_complex
|
def test_cgi_cookie_new_complex
|
||||||
t = Time.gm(2030, 12, 31, 23, 59, 59)
|
t = Time.gm(2030, 12, 31, 23, 59, 59)
|
||||||
value = ['val1', '&<>"', "\xA5\xE0\xA5\xB9\xA5\xAB"]
|
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',
|
cookie = CGI::Cookie.new('name'=>'name1',
|
||||||
'value'=>value,
|
'value'=>value,
|
||||||
'path'=>'/cgi-bin/myapp/',
|
'path'=>'/cgi-bin/myapp/',
|
||||||
|
|
|
@ -124,7 +124,7 @@ class CGICoreTest < Test::Unit::TestCase
|
||||||
$stdin = StringIO.new
|
$stdin = StringIO.new
|
||||||
$stdin << query_str
|
$stdin << query_str
|
||||||
$stdin.rewind
|
$stdin.rewind
|
||||||
if RUBY_VERSION>="1.9.0"
|
if defined?(::Encoding)
|
||||||
hash={}
|
hash={}
|
||||||
cgi = CGI.new(:accept_charset=>"UTF-8"){|key,val|hash[key]=val}
|
cgi = CGI.new(:accept_charset=>"UTF-8"){|key,val|hash[key]=val}
|
||||||
## cgi[]
|
## cgi[]
|
||||||
|
@ -251,7 +251,7 @@ class CGICoreTest < Test::Unit::TestCase
|
||||||
"Content-Length: 22\r\n" +
|
"Content-Length: 22\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
euc_str
|
euc_str
|
||||||
if RUBY_VERSION>="1.9"
|
if defined?(::Encoding)
|
||||||
actual.force_encoding("ASCII-8BIT")
|
actual.force_encoding("ASCII-8BIT")
|
||||||
expected.force_encoding("ASCII-8BIT")
|
expected.force_encoding("ASCII-8BIT")
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,7 +32,7 @@ class MultiPart
|
||||||
def initialize(boundary=nil)
|
def initialize(boundary=nil)
|
||||||
@boundary = boundary || create_boundary()
|
@boundary = boundary || create_boundary()
|
||||||
@buf = ''
|
@buf = ''
|
||||||
@buf.force_encoding("ascii-8bit") if RUBY_VERSION>="1.9"
|
@buf.force_encoding(::Encoding::ASCII_8BIT) if defined?(::Encoding)
|
||||||
end
|
end
|
||||||
attr_reader :boundary
|
attr_reader :boundary
|
||||||
|
|
||||||
|
@ -44,11 +44,8 @@ class MultiPart
|
||||||
buf << "Content-Disposition: form-data: name=\"#{name}\"#{s}\r\n"
|
buf << "Content-Disposition: form-data: name=\"#{name}\"#{s}\r\n"
|
||||||
buf << "Content-Type: #{content_type}\r\n" if content_type
|
buf << "Content-Type: #{content_type}\r\n" if content_type
|
||||||
buf << "\r\n"
|
buf << "\r\n"
|
||||||
if RUBY_VERSION>="1.9"
|
value = value.dup.force_encoding(::Encoding::ASCII_8BIT) if defined?(::Encoding)
|
||||||
buf << value.dup.force_encoding("ASCII-8BIT")
|
|
||||||
else
|
|
||||||
buf << value
|
buf << value
|
||||||
end
|
|
||||||
buf << "\r\n"
|
buf << "\r\n"
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
@ -192,7 +189,7 @@ class CGIMultipartTest < Test::Unit::TestCase
|
||||||
{:name=>'image1', :value=>_read('small.png'),
|
{:name=>'image1', :value=>_read('small.png'),
|
||||||
:filename=>'small.png', :content_type=>'image/png'}, # small image
|
: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
|
@expected_class = StringIO
|
||||||
_test_multipart()
|
_test_multipart()
|
||||||
end
|
end
|
||||||
|
@ -208,7 +205,7 @@ class CGIMultipartTest < Test::Unit::TestCase
|
||||||
{:name=>'image1', :value=>_read('large.png'),
|
{:name=>'image1', :value=>_read('large.png'),
|
||||||
:filename=>'large.png', :content_type=>'image/png'}, # large image
|
: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
|
@expected_class = Tempfile
|
||||||
_test_multipart()
|
_test_multipart()
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,7 +27,7 @@ class CGISessionTest < Test::Unit::TestCase
|
||||||
}
|
}
|
||||||
value1="value1"
|
value1="value1"
|
||||||
value2="\x8F\xBC\x8D]"
|
value2="\x8F\xBC\x8D]"
|
||||||
value2.force_encoding("SJIS") if RUBY_VERSION>="1.9"
|
value2.force_encoding("SJIS") if defined?(::Encoding)
|
||||||
ENV.update(@environ)
|
ENV.update(@environ)
|
||||||
cgi = CGI.new
|
cgi = CGI.new
|
||||||
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir)
|
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir)
|
||||||
|
@ -65,7 +65,7 @@ class CGISessionTest < Test::Unit::TestCase
|
||||||
}
|
}
|
||||||
value1="value1"
|
value1="value1"
|
||||||
value2="\x8F\xBC\x8D]"
|
value2="\x8F\xBC\x8D]"
|
||||||
value2.force_encoding("SJIS") if RUBY_VERSION>="1.9"
|
value2.force_encoding("SJIS") if defined?(::Encoding)
|
||||||
ENV.update(@environ)
|
ENV.update(@environ)
|
||||||
cgi = CGI.new
|
cgi = CGI.new
|
||||||
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"database_manager"=>CGI::Session::PStore)
|
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"database_manager"=>CGI::Session::PStore)
|
||||||
|
@ -102,7 +102,7 @@ class CGISessionTest < Test::Unit::TestCase
|
||||||
}
|
}
|
||||||
value1="value1"
|
value1="value1"
|
||||||
value2="\x8F\xBC\x8D]"
|
value2="\x8F\xBC\x8D]"
|
||||||
value2.force_encoding("SJIS") if RUBY_VERSION>="1.9"
|
value2.force_encoding("SJIS") if defined?(::Encoding)
|
||||||
ENV.update(@environ)
|
ENV.update(@environ)
|
||||||
cgi = CGI.new
|
cgi = CGI.new
|
||||||
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"session_id"=>"foo")
|
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"session_id"=>"foo")
|
||||||
|
@ -142,7 +142,7 @@ class CGISessionTest < Test::Unit::TestCase
|
||||||
}
|
}
|
||||||
value1="value1"
|
value1="value1"
|
||||||
value2="\x8F\xBC\x8D]"
|
value2="\x8F\xBC\x8D]"
|
||||||
value2.force_encoding("SJIS") if RUBY_VERSION>="1.9"
|
value2.force_encoding("SJIS") if defined?(::Encoding)
|
||||||
ENV.update(@environ)
|
ENV.update(@environ)
|
||||||
cgi = CGI.new
|
cgi = CGI.new
|
||||||
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"session_key"=>"bar")
|
session = CGI::Session.new(cgi,"tmpdir"=>@session_dir,"session_key"=>"bar")
|
||||||
|
|
|
@ -9,7 +9,7 @@ class CGIUtilTest < Test::Unit::TestCase
|
||||||
def setup
|
def setup
|
||||||
ENV['REQUEST_METHOD'] = 'GET'
|
ENV['REQUEST_METHOD'] = 'GET'
|
||||||
@str1="&<>\" \xE3\x82\x86\xE3\x82\x93\xE3\x82\x86\xE3\x82\x93"
|
@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
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
|
@ -21,12 +21,12 @@ class CGIUtilTest < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_cgi_escape
|
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', 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
|
end
|
||||||
|
|
||||||
def test_cgi_unescape
|
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, 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
|
end
|
||||||
|
|
||||||
def test_cgi_pretty
|
def test_cgi_pretty
|
||||||
|
|
Загрузка…
Ссылка в новой задаче