summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--lib/rubygems.rb5
-rw-r--r--test/rubygems/test_gem.rb28
3 files changed, 39 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 423b17f98c..8de428195b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Wed Feb 13 06:05:52 2013 Eric Hodel <drbrain@segment7.net>
+
+ * 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@fsij.org>
* ext/socket/extconf.rb: test functions just after struct members.
diff --git a/lib/rubygems.rb b/lib/rubygems.rb
index 039d26c1fe..177774376e 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -475,7 +475,9 @@ module Gem
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
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
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index fdeef699d4..bf77009ca6 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -1,3 +1,4 @@
+# coding: US-ASCII
require 'rubygems/test_case'
require 'rubygems'
require 'rubygems/installer'
@@ -1237,6 +1238,33 @@ class TestGem < Gem::TestCase
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