From 1e5a4ba48cbe4bf59403d93a02d15d1e14c2afc5 Mon Sep 17 00:00:00 2001 From: Norman Clarke Date: Mon, 8 Jun 2015 15:48:42 -0300 Subject: [PATCH] Handle parser edge case with '!' and '&' Treat '!' and '&' as operators when immediately followed by interpolation. Resolves #841 --- lib/haml/parser.rb | 4 ++-- test/engine_test.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/haml/parser.rb b/lib/haml/parser.rb index 3ffb37ab9b..c6dfdcc9f7 100644 --- a/lib/haml/parser.rb +++ b/lib/haml/parser.rb @@ -236,7 +236,7 @@ def process_line(line) return push plain(line.strip!(3), :escape_html) if line.text[1, 2] == '==' return push script(line.strip!(2), :escape_html) if line.text[1] == SCRIPT return push flat_script(line.strip!(2), :escape_html) if line.text[1] == FLAT_SCRIPT - return push plain(line.strip!(1), :escape_html) if line.text[1] == ?\s + return push plain(line.strip!(1), :escape_html) if line.text[1] == ?\s || line.text[1..2] == '#{' push plain(line) when SCRIPT return push plain(line.strip!(2)) if line.text[1] == SCRIPT @@ -252,7 +252,7 @@ def process_line(line) return push plain(line.strip!(3), false) if line.text[1, 2] == '==' return push script(line.strip!(2), false) if line.text[1] == SCRIPT return push flat_script(line.strip!(2), false) if line.text[1] == FLAT_SCRIPT - return push plain(line.strip!(1), false) if line.text[1] == ?\s + return push plain(line.strip!(1), false) if line.text[1] == ?\s || line.text[1..2] == '#{' push plain(line) when ESCAPE line.text = line.text[1..-1] diff --git a/test/engine_test.rb b/test/engine_test.rb index c25dc98554..22f17398a8 100644 --- a/test/engine_test.rb +++ b/test/engine_test.rb @@ -1032,11 +1032,21 @@ def test_escaped_string_interpolation assert_equal("

\n 4&<\n

\n", render("%p\n & \#{2+2}&\#{'<'}", :escape_html => false)) end + def test_escaped_string_interpolation_with_no_space + assert_equal("<br>\n", render('&#{"
"}')) + assert_equal("<br>\n", render('%span&#{"
"}')) + end + def test_unescaped_string_interpolation assert_equal("

\n 4&<\n

\n", render("%p\n ! \#{2+2}&\#{'<'}", :escape_html => true)) assert_equal("

\n 4&<\n

\n", render("%p\n ! \#{2+2}&\#{'<'}", :escape_html => false)) end + def test_unescaped_string_interpolation_with_no_space + assert_equal("
\n", render('!#{"
"}')) + assert_equal("
\n", render('%span!#{"
"}')) + end + def test_scripts_should_respect_escape_html_option assert_equal("

\n foo & bar\n

\n", render("%p\n = 'foo & bar'", :escape_html => true)) assert_equal("

\n foo & bar\n

\n", render("%p\n = 'foo & bar'", :escape_html => false))