Skip to content
This repository has been archived by the owner on Aug 8, 2019. It is now read-only.

Commit

Permalink
Fix engine bug where safe content was marked as unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
José Valim committed Jul 1, 2014
1 parent 2fe314b commit 3e11d0f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/phoenix/html/engine.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ defmodule Phoenix.Html.Engine do

def handle_text(buffer, text) do
quote do
{:safe, unquote(buffer) <> unquote(text)}
{:safe, unquote(Html.unsafe(buffer)) <> unquote(text)}
end
end

def handle_expr(buffer, "=", expr) do
expr = transform(expr)
buffer = Html.unsafe(buffer)

quote do
{:safe, quote do
buff = unquote(buffer)
buff <> Safe.to_string(unquote(expr))
end
end}
end

def handle_expr(buffer, "", expr) do
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/templates/within.html.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= within {MyApp.Views, "layouts/application.html"} do %><%= {:safe, "<>"} %><% end %>
5 changes: 5 additions & 0 deletions test/phoenix/template/compiler_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ defmodule Phoenix.Template.CompilerTest do
assert html == {:safe, "<html>\n <body>\n <div>Show! hello!</div>\n\n </body>\n</html>\n"}
end

test "compiler renders application layout with safe embed" do
html = MyApp.Views.render("within.html")
assert html == {:safe, "<html>\n <body>\n <>\n </body>\n</html>\n"}
end

test "compiler renders application layout with safe nested template" do
html = MyApp.Views.render("show.html",
within: {MyApp.Views, "layouts/application.html"},
Expand Down

0 comments on commit 3e11d0f

Please sign in to comment.