[前][次][番号順一覧][スレッド一覧]

ruby-changes:14326

From: nobu <ko1@a...>
Date: Wed, 23 Dec 2009 09:14:59 +0900 (JST)
Subject: [ruby-changes:14326] Ruby:r26154 (trunk): * test/cgi: check by Encoding.

nobu	2009-12-23 09:14:48 +0900 (Wed, 23 Dec 2009)

  New Revision: 26154

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26154

  Log:
    * test/cgi: check by Encoding.

  Modified files:
    trunk/test/cgi/test_cgi_cookie.rb
    trunk/test/cgi/test_cgi_core.rb
    trunk/test/cgi/test_cgi_multipart.rb
    trunk/test/cgi/test_cgi_session.rb
    trunk/test/cgi/test_cgi_util.rb

Index: test/cgi/test_cgi_util.rb
===================================================================
--- test/cgi/test_cgi_util.rb	(revision 26153)
+++ test/cgi/test_cgi_util.rb	(revision 26154)
@@ -9,7 +9,7 @@
   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 @@
 
   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
Index: test/cgi/test_cgi_multipart.rb
===================================================================
--- test/cgi/test_cgi_multipart.rb	(revision 26153)
+++ test/cgi/test_cgi_multipart.rb	(revision 26154)
@@ -32,7 +32,7 @@
   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 @@
     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 @@
       {: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 @@
       {: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
Index: test/cgi/test_cgi_session.rb
===================================================================
--- test/cgi/test_cgi_session.rb	(revision 26153)
+++ test/cgi/test_cgi_session.rb	(revision 26154)
@@ -27,7 +27,7 @@
     }
     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 @@
     }
     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 @@
     }
     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 @@
     }
     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")
Index: test/cgi/test_cgi_core.rb
===================================================================
--- test/cgi/test_cgi_core.rb	(revision 26153)
+++ test/cgi/test_cgi_core.rb	(revision 26154)
@@ -124,7 +124,7 @@
     $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 @@
                "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
Index: test/cgi/test_cgi_cookie.rb
===================================================================
--- test/cgi/test_cgi_cookie.rb	(revision 26153)
+++ test/cgi/test_cgi_cookie.rb	(revision 26154)
@@ -9,7 +9,7 @@
   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 @@
   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/',

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]