You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We found some issues with case/when statements when parsing ERB templates:
What doesn't work
erb_content=<<~EOS <% case 1 %> <% when 1 %>foo! <% end %>EOSsrc=ERB.new(erb_content).src# #coding:UTF-8# _erbout = +''; case 1 ; _erbout.<< "\n".freeze# ; when 1 ; _erbout.<< "foo!\n".freeze# ; end ; _erbout.<< "\n".freeze# ; _erbouteval(src)# (eval):2: syntax error, unexpected local variable or method, expecting `when' (SyntaxError)# ...erbout = +''; case 1 ; _erbout.<< "\n".freeze# ... ^~~~~~~# (eval):3: syntax error, unexpected `when', expecting end-of-input# ; when 1 ; _erbout.<< "foo!\n".free...# ^~~~
What works
erb_content=<<~EOS <% case 1 when 1 %>foo! <% end %>EOSsrc=ERB.new(erb_content).src# #coding:UTF-8# _erbout = +''; case 1 # when 1 ; _erbout.<< "foo!\n".freeze# ; end ; _erbout.<< "\n".freeze# ; _erbouteval(src)# "foo!\n\n"
It was tested on Ruby 3.0.3 and 2.7.2
The text was updated successfully, but these errors were encountered:
I'm not sure if we've ever supported it. Unlike Haml, ERB doesn't do anything clever whether you embed case-when or not. You have to carefully write your template or choose a proper option to make it work. e.g. This should work:
erb_content=<<~EOS <% case 1 %> <% when 1 %>foo! <% end %>EOSsrc=ERB.new(erb_content,trim_mode: '>').src
We found some issues with
case
/when
statements when parsing ERB templates:What doesn't work
What works
It was tested on Ruby
3.0.3
and2.7.2
The text was updated successfully, but these errors were encountered: