Skip to content

Commit 49e7683

Browse files
author
José Valim
committed
Ensure blocks do not clobber eex buffer
Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
1 parent 7963e44 commit 49e7683

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

lib/eex/lib/eex/engine.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,16 @@ defmodule EEx.Engine do
9898
"""
9999
def handle_expr(buffer, "=", expr) do
100100
quote do
101-
tmp = unquote(buffer)
102-
tmp <> String.Chars.to_string(unquote(expr))
101+
tmp1 = unquote(buffer)
102+
tmp1 <> String.Chars.to_string(unquote(expr))
103103
end
104104
end
105105

106106
def handle_expr(buffer, "", expr) do
107107
quote do
108-
tmp = unquote(buffer)
108+
tmp2 = unquote(buffer)
109109
unquote(expr)
110-
tmp
110+
tmp2
111111
end
112112
end
113113
end

lib/eex/test/eex_test.exs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ Number <%= x %>
252252
assert_eval expected, string
253253
end
254254

255-
test "do not consider already finished functions" do
255+
test "properly handle functions on the left side of clauses" do
256256
expected = """
257257
foo
258258
@@ -287,6 +287,18 @@ foo
287287
assert_eval "\n\n Good\n \n", string
288288
end
289289

290+
test "evaluates expressions with buffers" do
291+
string = """
292+
<%= 123 %>
293+
<% if true do %>
294+
<%= 456 %>
295+
<% end %>
296+
<%= 789 %>
297+
"""
298+
299+
assert_eval "123\n\n789\n", string
300+
end
301+
290302
test "for comprehensions" do
291303
string = """
292304
<%= for _name <- packages || [] do %>

0 commit comments

Comments
 (0)