diff options
Diffstat (limited to 'actionview')
-rw-r--r-- | actionview/lib/action_view/buffers.rb | 5 | ||||
-rw-r--r-- | actionview/lib/action_view/template/handlers/erb.rb | 4 | ||||
-rw-r--r-- | actionview/test/fixtures/test/nil_return.erb | 1 | ||||
-rw-r--r-- | actionview/test/template/compiled_templates_test.rb | 4 |
4 files changed, 12 insertions, 2 deletions
diff --git a/actionview/lib/action_view/buffers.rb b/actionview/lib/action_view/buffers.rb index 50bc315700..be5d86b1dc 100644 --- a/actionview/lib/action_view/buffers.rb +++ b/actionview/lib/action_view/buffers.rb @@ -13,6 +13,11 @@ module ActionView end alias :append= :<< + def safe_expr_append=(val) + return self if val.nil? + safe_concat val.to_s + end + alias :safe_append= :safe_concat end diff --git a/actionview/lib/action_view/template/handlers/erb.rb b/actionview/lib/action_view/template/handlers/erb.rb index 4523060442..3c2224fbf5 100644 --- a/actionview/lib/action_view/template/handlers/erb.rb +++ b/actionview/lib/action_view/template/handlers/erb.rb @@ -49,9 +49,9 @@ module ActionView def add_expr_escaped(src, code) flush_newline_if_pending(src) if code =~ BLOCK_EXPR - src << "@output_buffer.safe_append= " << code + src << "@output_buffer.safe_expr_append= " << code else - src << "@output_buffer.safe_append=(" << code << ");" + src << "@output_buffer.safe_expr_append=(" << code << ");" end end diff --git a/actionview/test/fixtures/test/nil_return.erb b/actionview/test/fixtures/test/nil_return.erb new file mode 100644 index 0000000000..90ce3881f6 --- /dev/null +++ b/actionview/test/fixtures/test/nil_return.erb @@ -0,0 +1 @@ +This is nil: <%== nil %> diff --git a/actionview/test/template/compiled_templates_test.rb b/actionview/test/template/compiled_templates_test.rb index b84aca6746..f6c1283b92 100644 --- a/actionview/test/template/compiled_templates_test.rb +++ b/actionview/test/template/compiled_templates_test.rb @@ -5,6 +5,10 @@ class CompiledTemplatesTest < ActiveSupport::TestCase ActionView::LookupContext::DetailsKey.clear end + def test_template_with_nil_erb_return + assert_equal "This is nil: \n", render(:template => "test/nil_return") + end + def test_template_gets_recompiled_when_using_different_keys_in_local_assigns assert_equal "one", render(:file => "test/render_file_with_locals_and_default") assert_equal "two", render(:file => "test/render_file_with_locals_and_default", :locals => { :secret => "two" }) |