Skip to content
This repository
Browse code

fix for AS Gzip returning a UTF-8 string in Ruby 1.9 when it is actua…

…lly binary [#6386 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 31690ea8b3420aea4ea4427e1599665d093c974f 1 parent ff00cd2
Josh Kalderimis authored February 09, 2011 josevalim committed February 09, 2011
4  activesupport/lib/active_support/gzip.rb
@@ -5,6 +5,10 @@ module ActiveSupport
5 5
   # A convenient wrapper for the zlib standard library that allows compression/decompression of strings with gzip.
6 6
   module Gzip
7 7
     class Stream < StringIO
  8
+      def initialize(*)
  9
+         super
  10
+         set_encoding "BINARY" if "".encoding_aware?
  11
+       end
8 12
       def close; rewind; end
9 13
     end
10 14
 
10  activesupport/test/gzip_test.rb
@@ -4,4 +4,14 @@ class GzipTest < Test::Unit::TestCase
4 4
   def test_compress_should_decompress_to_the_same_value
5 5
     assert_equal "Hello World", ActiveSupport::Gzip.decompress(ActiveSupport::Gzip.compress("Hello World"))
6 6
   end
  7
+
  8
+  def test_compress_should_return_a_binary_string
  9
+    compressed = ActiveSupport::Gzip.compress('')
  10
+
  11
+    if "".encoding_aware?
  12
+      assert_equal Encoding.find('binary'), compressed.encoding
  13
+    end
  14
+
  15
+    assert !compressed.blank?, "a compressed blank string should not be blank"
  16
+  end
7 17
 end

0 notes on commit 31690ea

Please sign in to comment.
Something went wrong with that request. Please try again.