Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions actionview/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
* Fix the `capture` view helper compatibility with HAML and Slim

When a blank string was captured in HAML or Slim (and possibly other template engines)
it would instead return the entire buffer.

*Jean Boussier*

* Updated `@rails/ujs` files to ignore certain data-* attributes when element is contenteditable.

This fix was already landed in >= 7.0.4.3, < 7.1.0.
Expand Down
8 changes: 7 additions & 1 deletion actionview/lib/action_view/helpers/capture_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ def capture(*args, &block)
@output_buffer ||= ActionView::OutputBuffer.new
buffer = @output_buffer.capture { value = yield(*args) }

case string = buffer.presence || value
string = if @output_buffer.equal?(value)
buffer
else
buffer.presence || value
end

case string
when OutputBuffer
string.to_s
when ActiveSupport::SafeBuffer
Expand Down
10 changes: 10 additions & 0 deletions actionview/test/template/capture_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ def test_with_output_buffer_does_not_assume_there_is_an_output_buffer
assert_equal "", @av.with_output_buffer { }.to_s
end

def test_ignore_the_block_return_if_its_the_buffer
@av.output_buffer << "something"
string = @av.capture do
@av.output_buffer << "foo"
@av.output_buffer << "bar"
@av.output_buffer
end
assert_equal "foobar", string
end

def alt_encoding(output_buffer)
output_buffer.encoding == Encoding::US_ASCII ? Encoding::UTF_8 : Encoding::US_ASCII
end
Expand Down