mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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>
This commit is contained in:
parent
e466354edb
commit
a6e95ba554
3 changed files with 24 additions and 2 deletions
|
@ -101,7 +101,11 @@ module ActiveSupport
|
|||
@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
|
||||
|
|
|
@ -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 @@ class BufferedLoggerTest < Test::Unit::TestCase
|
|||
@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
|
||||
|
|
|
@ -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 @@ module MultibyteTestHelpers
|
|||
def assert_equal_codepoints(expected, actual, message=nil)
|
||||
assert_equal(inspect_codepoints(expected), inspect_codepoints(actual), message)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue