mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Fix a crash in StringSplitter
Close https://github.com/haml/haml/issues/1096 Applying https://github.com/judofyr/temple/pull/138 to Haml's fork until it's merged to upstream.
This commit is contained in:
parent
7e31a8e868
commit
e3bd326b3d
2 changed files with 20 additions and 0 deletions
|
@ -46,6 +46,7 @@ module Haml
|
||||||
|
|
||||||
case type
|
case type
|
||||||
when :on_tstring_content
|
when :on_tstring_content
|
||||||
|
beg_str, end_str = escape_quotes(beg_str, end_str)
|
||||||
exps << [:static, eval("#{beg_str}#{str}#{end_str}").to_s]
|
exps << [:static, eval("#{beg_str}#{str}#{end_str}").to_s]
|
||||||
when :on_embexpr_beg
|
when :on_embexpr_beg
|
||||||
embedded = shift_balanced_embexpr(tokens)
|
embedded = shift_balanced_embexpr(tokens)
|
||||||
|
@ -54,6 +55,16 @@ module Haml
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Some quotes are split-unsafe. Replace such quotes with null characters.
|
||||||
|
def escape_quotes(beg_str, end_str)
|
||||||
|
case [beg_str[-1], end_str]
|
||||||
|
when ['(', ')'], ['[', ']'], ['{', '}']
|
||||||
|
[beg_str.sub(/.\z/) { "\0" }, "\0"]
|
||||||
|
else
|
||||||
|
[beg_str, end_str]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def shift_balanced_embexpr(tokens)
|
def shift_balanced_embexpr(tokens)
|
||||||
String.new.tap do |embedded|
|
String.new.tap do |embedded|
|
||||||
embexpr_open = 1
|
embexpr_open = 1
|
||||||
|
|
|
@ -78,6 +78,15 @@ describe Haml::Engine do
|
||||||
HAML
|
HAML
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'renders %() string attributes' do
|
||||||
|
assert_render(<<-'HTML'.unindent, <<-'HAML'.unindent)
|
||||||
|
<p title='foo(a)'></p>
|
||||||
|
HTML
|
||||||
|
- some_local_variable = 'a'
|
||||||
|
%p{ title: %(foo(#{some_local_variable})) }
|
||||||
|
HAML
|
||||||
|
end
|
||||||
|
|
||||||
describe 'runtime attributes' do
|
describe 'runtime attributes' do
|
||||||
it 'renders runtime hash attribute' do
|
it 'renders runtime hash attribute' do
|
||||||
assert_render(<<-HTML.unindent, <<-HAML.unindent)
|
assert_render(<<-HTML.unindent, <<-HAML.unindent)
|
||||||
|
|
Loading…
Reference in a new issue