mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Ruby 1.9: flushing the output buffer preserves its encoding
This commit is contained in:
@@ -124,7 +124,11 @@ module ActionView
|
||||
|
||||
# Use an alternate output buffer for the duration of the block.
|
||||
# Defaults to a new empty string.
|
||||
def with_output_buffer(buf = '') #:nodoc:
|
||||
def with_output_buffer(buf = nil) #:nodoc:
|
||||
unless buf
|
||||
buf = ''
|
||||
buf.force_encoding(output_buffer.encoding) if buf.respond_to?(:force_encoding)
|
||||
end
|
||||
self.output_buffer, old_buffer = buf, output_buffer
|
||||
yield
|
||||
output_buffer
|
||||
@@ -134,9 +138,12 @@ module ActionView
|
||||
|
||||
# Add the output buffer to the response body and start a new one.
|
||||
def flush_output_buffer #:nodoc:
|
||||
if output_buffer && output_buffer != ''
|
||||
if output_buffer && !output_buffer.empty?
|
||||
response.body_parts << output_buffer
|
||||
self.output_buffer = ''
|
||||
new = ''
|
||||
new.force_encoding(output_buffer.encoding) if new.respond_to?(:force_encoding)
|
||||
self.output_buffer = new
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -38,6 +38,17 @@ class OutputBufferTest < ActionController::TestCase
|
||||
assert_equal ['foo', 'bar'], body_parts
|
||||
end
|
||||
|
||||
if '1.9'.respond_to?(:force_encoding)
|
||||
test 'flushing preserves output buffer encoding' do
|
||||
original_buffer = ' '.force_encoding(Encoding::EUC_JP)
|
||||
@controller.template.output_buffer = original_buffer
|
||||
@controller.template.flush_output_buffer
|
||||
assert_equal ['foo', original_buffer], body_parts
|
||||
assert_not_equal original_buffer, output_buffer
|
||||
assert_equal Encoding::EUC_JP, output_buffer.encoding
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
def output_buffer
|
||||
@controller.template.output_buffer
|
||||
|
||||
Reference in New Issue
Block a user