diff options
Diffstat (limited to 'actionview')
-rw-r--r-- | actionview/CHANGELOG.md | 7 | ||||
-rw-r--r-- | actionview/lib/action_view/helpers/capture_helper.rb | 5 | ||||
-rw-r--r-- | actionview/test/template/capture_helper_test.rb | 4 | ||||
-rw-r--r-- | actionview/test/template/tag_helper_test.rb | 9 |
4 files changed, 12 insertions, 13 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index dbdf682614..729717608f 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,8 +1 @@ Please check [4-2-stable](https://github.com/rails/rails/blob/4-2-stable/actionview/CHANGELOG.md) for previous changes. - -* Restore old behaviour for `capture` to return value as is when passed non-String values. - - Fixes #17661. - - *Carsten Zimmermann* - diff --git a/actionview/lib/action_view/helpers/capture_helper.rb b/actionview/lib/action_view/helpers/capture_helper.rb index 7884e4f1f1..5a3223968f 100644 --- a/actionview/lib/action_view/helpers/capture_helper.rb +++ b/actionview/lib/action_view/helpers/capture_helper.rb @@ -31,12 +31,13 @@ module ActionView # <head><title><%= @greeting %></title></head> # <body> # <b><%= @greeting %></b> - # </body></html> + # </body> + # </html> # def capture(*args) value = nil buffer = with_output_buffer { value = yield(*args) } - if string = buffer.presence || value + if string = buffer.presence || value and string.is_a?(String) ERB::Util.html_escape string end end diff --git a/actionview/test/template/capture_helper_test.rb b/actionview/test/template/capture_helper_test.rb index b2b8513d4f..f213da5934 100644 --- a/actionview/test/template/capture_helper_test.rb +++ b/actionview/test/template/capture_helper_test.rb @@ -24,8 +24,8 @@ class CaptureHelperTest < ActionView::TestCase assert_equal 'foobar', string end - def test_capture_returns_value_even_if_the_returned_value_is_not_a_string - assert_equal '1', @av.capture { 1 } + def test_capture_returns_nil_if_the_returned_value_is_not_a_string + assert_nil @av.capture { 1 } end def test_capture_escapes_html diff --git a/actionview/test/template/tag_helper_test.rb b/actionview/test/template/tag_helper_test.rb index 2b3915edcd..d037447567 100644 --- a/actionview/test/template/tag_helper_test.rb +++ b/actionview/test/template/tag_helper_test.rb @@ -50,6 +50,11 @@ class TagHelperTest < ActionView::TestCase assert_dom_equal "<div>Hello world!</div>", buffer end + def test_content_tag_with_block_in_erb_containing_non_displayed_erb + buffer = render_erb("<%= content_tag(:p) do %><% 1 %><% end %>") + assert_dom_equal "<p></p>", buffer + end + def test_content_tag_with_block_and_options_in_erb buffer = render_erb("<%= content_tag(:div, :class => 'green') do %>Hello world!<% end %>") assert_dom_equal %(<div class="green">Hello world!</div>), buffer @@ -65,8 +70,8 @@ class TagHelperTest < ActionView::TestCase end def test_content_tag_with_block_and_non_string_outside_out_of_erb - assert_equal content_tag("p", "1.0", nil, false), - content_tag("p") { 1.0 } + assert_equal content_tag("p"), + content_tag("p") { 3.times { "do_something" } } end def test_content_tag_nested_in_content_tag_out_of_erb |