Skip to content

Commit 2a13c5b

Browse files
authored
handle closing interpolation without opening brace in attrs (#4129)
Closes #4117.
1 parent 88e5eca commit 2a13c5b

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

lib/phoenix_live_view/tag_engine/tokenizer.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,10 @@ defmodule Phoenix.LiveView.TagEngine.Tokenizer do
491491

492492
## handle_attr_name
493493

494+
defp handle_attr_name(<<"}"::utf8, _rest::binary>>, column, _buffer) do
495+
{:error, "expected attribute, but found end of interpolation: }", column}
496+
end
497+
494498
defp handle_attr_name(<<c::utf8, _rest::binary>>, column, _buffer)
495499
when c in @quote_chars do
496500
{:error, "invalid character in attribute name: #{<<c>>}", column}

test/phoenix_live_view/html_engine_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,14 +738,14 @@ defmodule Phoenix.LiveView.HTMLEngineTest do
738738
test/phoenix_live_view/html_engine_test.exs:2:38: unsupported attribute \":bar\" in local component: local_function_component
739739
|
740740
1 | <br>
741-
2 | <.local_function_component value='1' :bar=\"1\"}
741+
2 | <.local_function_component value='1' :bar=\"1\" />
742742
| ^\
743743
"""
744744

745745
assert_raise(ParseError, message, fn ->
746746
eval("""
747747
<br>
748-
<.local_function_component value='1' :bar="1"}
748+
<.local_function_component value='1' :bar="1" />
749749
/>
750750
""")
751751
end)

test/phoenix_live_view/heex/tokenizer_test.exs renamed to test/phoenix_live_view/tag_engine/tokenizer_test.exs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,19 @@ defmodule Phoenix.LiveView.TagEngine.TokenizerTest do
443443
tokenize(~S(<div class={"test"}">))
444444
end
445445
end
446+
447+
test "raise on missing opening interpolation" do
448+
message = """
449+
nofile:1:29: expected attribute, but found end of interpolation: }
450+
|
451+
1 | <div class=\"image-container\"}>
452+
| ^\
453+
"""
454+
455+
assert_raise ParseError, message, fn ->
456+
tokenize(~S(<div class="image-container"}>))
457+
end
458+
end
446459
end
447460

448461
describe "boolean attributes" do

0 commit comments

Comments
 (0)