Skip to content

Commit f4c6d5c

Browse files
committed
Do not affect curly interpolation on style/script tags, closes #3714
1 parent 2f3fc95 commit f4c6d5c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/phoenix_live_view/tokenizer.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,8 @@ defmodule Phoenix.LiveView.Tokenizer do
455455
acc = put_attr(acc, name, attr_meta, value)
456456

457457
state =
458-
if name == "phx-no-curly-interpolation" and state.braces == :enabled do
458+
if name == "phx-no-curly-interpolation" and state.braces == :enabled and
459+
not script_or_style?(acc) do
459460
%{state | braces: 0}
460461
else
461462
state
@@ -469,6 +470,9 @@ defmodule Phoenix.LiveView.Tokenizer do
469470
end
470471
end
471472

473+
defp script_or_style?([{:tag, name, _, _} | _]) when name in ~w(script style), do: true
474+
defp script_or_style?(_), do: false
475+
472476
## handle_root_attribute
473477

474478
defp handle_root_attribute(text, line, column, acc, state) do

test/phoenix_live_view/html_engine_test.exs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ defmodule Phoenix.LiveView.HTMLEngineTest do
121121
assert render("""
122122
<div phx-no-curly-interpolation>{open}{<%= :eval %>}{close}</div>
123123
""") == "<div>{open}{eval}{close}</div>"
124+
125+
assert render("""
126+
{:pre}<style phx-no-curly-interpolation>{css}</style>{:post}
127+
""") == "pre<style>{css}</style>post"
128+
129+
assert render("""
130+
<div phx-no-curly-interpolation>{:pre}<style phx-no-curly-interpolation>{css}</style>{:post}</div>
131+
""") == "<div>{:pre}<style>{css}</style>{:post}</div>"
124132
end
125133

126134
test "handles string attributes" do

0 commit comments

Comments
 (0)