Skip to content

Commit

Permalink
Do not taint on |> var
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Oct 27, 2023
1 parent 2df6832 commit 6a3b33e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/phoenix_live_view/engine.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,13 @@ defmodule Phoenix.LiveView.Engine do
{expr, vars, assigns}
end

# Ignore right side of |> if a variable
defp analyze({:|>, meta, [left, {_, _, context} = right]}, vars, assigns, caller)
when is_atom(context) do
{left, vars, assigns} = analyze(left, vars, assigns, caller)
{{:|>, meta, [left, right]}, vars, assigns}
end

# Ignore binary modifiers
defp analyze({:"::", meta, [left, right]}, vars, assigns, caller) do
{left, vars, assigns} = analyze(left, vars, assigns, caller)
Expand Down
13 changes: 13 additions & 0 deletions test/phoenix_live_view/engine_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,19 @@ defmodule Phoenix.LiveView.EngineTest do
assert changed(template, %{}, %{}) == ["3", "3"]
end

test "does not render dynamic if it has variables on the right side of the pipe" do
template = "<%= @foo |> Kernel.+(@bar) |> is_integer %>"
assert changed(template, %{foo: 1, bar: 2}, nil) == ["true"]
assert changed(template, %{foo: 1, bar: 2}, %{}) == [nil]
assert changed(template, %{foo: 1, bar: 2}, %{foo: true}) == ["true"]
assert changed(template, %{foo: 1, bar: 2}, %{bar: true}) == ["true"]

template = "<%= @foo |> is_integer |> is_boolean %>"
assert changed(template, %{foo: 1}, nil) == ["true"]
assert changed(template, %{foo: 1}, %{}) == [nil]
assert changed(template, %{foo: 1}, %{foo: true}) == ["true"]
end

test "does not render dynamic for special variables" do
template = "<%= __MODULE__ %>"
assert changed(template, %{}, nil) == [""]
Expand Down

0 comments on commit 6a3b33e

Please sign in to comment.