I have the following flow:
- A user is presented with a form.
- He fills in the form fields, and submits to the controller, which persists this to the DB
- On another page, the Controller gets this record from the DB, and passes it to the view
- The view captures it as a javascript variable:
var foo = '${user.bar}';
Now, if the user enters this string in the form:
I have a quote - ' - very dangerous
then the quote is passed through all the way to the DB and back, and results in a corrupt javascript statement:
var foo = 'I have a quote - ' - very dangerous';
What is the best place to escape this character, and how? I don't want to do it manually for each template usage, it's tedious and error prone.
${user.bar.addSlashes().raw()}
? It is rather verbose and error prone. playframework.org/documentation/1.2.4/javaextensions – Sengvar foo = '@user.bar.escapeJavaScript()';
. Check playframework.org/modules/rythm for more about Rythm template engine – Susquehanna