summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/cgi/test_cgi_cookie.rb4
-rw-r--r--test/cgi/test_cgi_core.rb4
-rw-r--r--test/cgi/test_cgi_multipart.rb13
-rw-r--r--test/cgi/test_cgi_session.rb8
-rw-r--r--test/cgi/test_cgi_util.rb6
5 files changed, 16 insertions, 19 deletions
diff --git a/test/cgi/test_cgi_cookie.rb b/test/cgi/test_cgi_cookie.rb
index c55b52ed03..c1c6a30e70 100644
--- a/test/cgi/test_cgi_cookie.rb
+++ b/test/cgi/test_cgi_cookie.rb
@@ -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/',
diff --git a/test/cgi/test_cgi_core.rb b/test/cgi/test_cgi_core.rb
index 3f75b04fd4..23b8891576 100644
--- a/test/cgi/test_cgi_core.rb
+++ b/test/cgi/test_cgi_core.rb
@@ -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
diff --git a/test/cgi/test_cgi_multipart.rb b/test/cgi/test_cgi_multipart.rb
index 717640e4f0..c123aa80b5 100644
--- a/test/cgi/test_cgi_multipart.rb
+++ b/test/cgi/test_cgi_multipart.rb
@@ -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
- buf << value
- end
+ value = value.dup.force_encoding(::Encoding::ASCII_8BIT) if defined?(::Encoding)
+ buf << value
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
diff --git a/test/cgi/test_cgi_session.rb b/test/cgi/test_cgi_session.rb
index 50e0f4af4d..f3b8e60865 100644
--- a/test/cgi/test_cgi_session.rb
+++ b/test/cgi/test_cgi_session.rb
@@ -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")
diff --git a/test/cgi/test_cgi_util.rb b/test/cgi/test_cgi_util.rb
index 3a891d6171..479df68159 100644
--- a/test/cgi/test_cgi_util.rb
+++ b/test/cgi/test_cgi_util.rb
@@ -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