Skip to content

Commit

Permalink
fix for AS Gzip returning a UTF-8 string in Ruby 1.9 when it is actua…
Browse files Browse the repository at this point in the history
…lly binary [#6386 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
joshk authored and josevalim committed Feb 9, 2011
1 parent 5046120 commit 3eb25fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions activesupport/lib/active_support/gzip.rb
Expand Up @@ -5,6 +5,10 @@ module ActiveSupport
# A convenient wrapper for the zlib standard library that allows compression/decompression of strings with gzip.
module Gzip
class Stream < StringIO
def initialize(*)
super
set_encoding "BINARY" if "".encoding_aware?
end
def close; rewind; end
end

Expand Down
10 changes: 10 additions & 0 deletions activesupport/test/gzip_test.rb
Expand Up @@ -4,4 +4,14 @@ class GzipTest < Test::Unit::TestCase
def test_compress_should_decompress_to_the_same_value
assert_equal "Hello World", ActiveSupport::Gzip.decompress(ActiveSupport::Gzip.compress("Hello World"))
end

def test_compress_should_return_a_binary_string
compressed = ActiveSupport::Gzip.compress('')

if "".encoding_aware?
assert_equal Encoding.find('binary'), compressed.encoding
end

assert !compressed.blank?, "a compressed blank string should not be blank"
end
end

0 comments on commit 3eb25fb

Please sign in to comment.