mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
handle <%== nil %> cases
This is much less common than string literal appends, so add a special
case method for it. Maybe fixes bug reported by @jeremy on 97ef636191
This commit is contained in:
parent
ac941096bf
commit
8a47e87267
4 changed files with 12 additions and 2 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
1
actionview/test/fixtures/test/nil_return.erb
vendored
Normal file
1
actionview/test/fixtures/test/nil_return.erb
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
This is nil: <%== nil %>
|
|
@ -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" })
|
||||
|
|
Loading…
Reference in a new issue