Open itsumura-h opened 2 years ago
Interesting idea - My only concern would be it interfering with some other nim syntax. What about adding another prefix to indicate escape; like '$!' instead of just '$' ?
i..e.
import templates
let x = "<script>alert("hello")</script>"
let dom = tmpli html"""
<p>$!x</p>
"""
assert dom == "<p><script>alert("hello")</script></p>"
@onionhammer
"!" means destructive change or doing something that should not be used but is unavoidably dangerous in other programming languages.
so "$!x" prefers be like dangerouslySetInnerHTML
in react, and if "$x" is escaped by default, it is safe.
Yeah good point. I wouldn't want to issue a breaking change for this, but syntactic sugar for escaping the HTML would be nice.
Variable should be xml encoded to prevent XSS https://nim-lang.org/docs/cgi.html#xmlEncode%2Cstring
so I propose a new syntax if possible
then it shoud be like this