Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix mixed encoding logs can't be logged.

[#4807 state:committed]

Signed-off-by: Kouhei Sutou <kou@cozmixng.org>
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
commit a6e95ba55401ddcaf9ef867a080b30c2d07c56ac 1 parent e466354
Kouhei Sutou kou authored jeremy committed
6 activesupport/lib/active_support/buffered_logger.rb
View
@@ -101,7 +101,11 @@ def flush
@guard.synchronize do
unless buffer.empty?
old_buffer = buffer
- @log.write(old_buffer.join)
+ all_content = StringIO.new
+ old_buffer.each do |content|
+ all_content << content
+ end
+ @log.write(all_content.string)
end
# Important to do this even if buffer was empty or else @buffer will
15 activesupport/test/buffered_logger_test.rb
View
@@ -1,9 +1,12 @@
require 'abstract_unit'
+require 'multibyte_test_helpers'
require 'stringio'
require 'fileutils'
require 'active_support/buffered_logger'
class BufferedLoggerTest < Test::Unit::TestCase
+ include MultibyteTestHelpers
+
Logger = ActiveSupport::BufferedLogger
def setup
@@ -146,4 +149,16 @@ def test_flush_should_remove_empty_buffers
@logger.expects :clear_buffer
@logger.flush
end
+
+ def test_buffer_multibyte
+ @logger.auto_flushing = 2
+ @logger.info(UNICODE_STRING)
+ @logger.info(BYTE_STRING)
+ assert @output.string.include?(UNICODE_STRING)
+ byte_string = @output.string.dup
+ if byte_string.respond_to?(:force_encoding)
+ byte_string.force_encoding("ASCII-8BIT")
+ end
+ assert byte_string.include?(BYTE_STRING)
+ end
end
5 activesupport/test/multibyte_test_helpers.rb
View
@@ -4,6 +4,9 @@ module MultibyteTestHelpers
UNICODE_STRING = 'こにちわ'
ASCII_STRING = 'ohayo'
BYTE_STRING = "\270\236\010\210\245"
+ if BYTE_STRING.respond_to?(:force_encoding)
+ BYTE_STRING.force_encoding("ASCII-8BIT")
+ end
def chars(str)
ActiveSupport::Multibyte::Chars.new(str)
@@ -16,4 +19,4 @@ def inspect_codepoints(str)
def assert_equal_codepoints(expected, actual, message=nil)
assert_equal(inspect_codepoints(expected), inspect_codepoints(actual), message)
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.