Replying to @coderbyheart

Use very restrictive code like:

const templateString = 'abc${val}def' // could come from a database ... const
val = 'f00'; console.log(templateString.replace(/${val}/g, val))

which replaces the exact instace of the placeholder, nothing else.

Sat, 09 Dec 2017 10:47:28 UTC

1 reply

Replying to @coderbyheart

Don't do things that evals all variables. In most cases (e.g. rendering an email
subject), the names of the variables are known and defined. Support only that.

In the original case of the code, there would have been ever only one
placeholder...