@@ -329,6 +329,12 @@ defmodule Phoenix.HTML do
329329 $("#container").append("<%= javascript_escape(render("post.html", post: @post)) %>");
330330
331331 It escapes quotes (double and single), double backslashes and others.
332+
333+ > #### Do not inject into template literals {: .error}
334+ >
335+ > Do not inject the result of `javascript_escape` into JavaScript
336+ > template literals (defined with backticks), given template functions
337+ > can change the meaning of the string in unsafe ways.
332338 """
333339 @ spec javascript_escape ( binary ) :: binary
334340 @ spec javascript_escape ( safe ) :: safe
@@ -353,7 +359,7 @@ defmodule Phoenix.HTML do
353359 defp javascript_escape ( << "\r \n " , t :: binary >> , acc ) ,
354360 do: javascript_escape ( t , << acc :: binary , ?\\ , ?n >> )
355361
356- defp javascript_escape ( << h , t :: binary >> , acc ) when h in [ ?" , ?' , ?\\ , ?` ] ,
362+ defp javascript_escape ( << h , t :: binary >> , acc ) when h in [ ?" , ?' , ?\\ , ?` , ?$ ] ,
357363 do: javascript_escape ( t , << acc :: binary , ?\\ , h >> )
358364
359365 defp javascript_escape ( << h , t :: binary >> , acc ) when h in [ ?\r , ?\n ] ,
0 commit comments