ruby-changes:27161
From: drbrain <ko1@a...>
Date: Wed, 13 Feb 2013 06:08:33 +0900 (JST)
Subject: [ruby-changes:27161] drbrain:r39213 (trunk): * lib/rubygems.rb: Return BINARY strings from Gem.gzip and Gem.gunzip.
drbrain 2013-02-13 06:06:36 +0900 (Wed, 13 Feb 2013) New Revision: 39213 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39213 Log: * lib/rubygems.rb: Return BINARY strings from Gem.gzip and Gem.gunzip. Fixes intermittent test failures. RubyGems issue #450 by Jeremey Kemper. * test/rubygems/test_gem.rb: Test for the above. Modified files: trunk/ChangeLog trunk/lib/rubygems.rb trunk/test/rubygems/test_gem.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 39212) +++ ChangeLog (revision 39213) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Feb 13 06:05:52 2013 Eric Hodel <drbrain@s...> + + * lib/rubygems.rb: Return BINARY strings from Gem.gzip and Gem.gunzip. + Fixes intermittent test failures. RubyGems issue #450 by Jeremey + Kemper. + * test/rubygems/test_gem.rb: Test for the above. + Wed Feb 13 05:49:21 2013 Tanaka Akira <akr@f...> * ext/socket/extconf.rb: test functions just after struct members. Index: lib/rubygems.rb =================================================================== --- lib/rubygems.rb (revision 39212) +++ lib/rubygems.rb (revision 39213) @@ -475,7 +475,9 @@ module Gem https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L475 require 'zlib' data = StringIO.new data - Zlib::GzipReader.new(data).read + unzipped = Zlib::GzipReader.new(data).read + unzipped.force_encoding Encoding::BINARY if Object.const_defined? :Encoding + unzipped end ## @@ -486,6 +488,7 @@ module Gem https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L488 require 'stringio' require 'zlib' zipped = StringIO.new + zipped.set_encoding Encoding::BINARY if Object.const_defined? :Encoding Zlib::GzipWriter.wrap zipped do |io| io.write data end Index: test/rubygems/test_gem.rb =================================================================== --- test/rubygems/test_gem.rb (revision 39212) +++ test/rubygems/test_gem.rb (revision 39213) @@ -1,3 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1 +# coding: US-ASCII require 'rubygems/test_case' require 'rubygems' require 'rubygems/installer' @@ -1237,6 +1238,33 @@ class TestGem < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem.rb#L1238 end end + def test_self_gunzip + input = "\x1F\x8B\b\0\xED\xA3\x1AQ\0\x03\xCBH" + + "\xCD\xC9\xC9\a\0\x86\xA6\x106\x05\0\0\0" + + output = Gem.gunzip input + + assert_equal 'hello', output + + return unless Object.const_defined? :Encoding + + assert_equal Encoding::BINARY, output.encoding + end + + def test_self_gzip + input = 'hello' + + output = Gem.gzip input + + zipped = StringIO.new output + + assert_equal 'hello', Zlib::GzipReader.new(zipped).read + + return unless Object.const_defined? :Encoding + + assert_equal Encoding::BINARY, output.encoding + end + if Gem.win_platform? && '1.9' > RUBY_VERSION # Ruby 1.9 properly handles ~ path expansion, so no need to run such tests. def test_self_user_home_userprofile -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/