Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Twig.js's autoescaping currently has some potentially unexpected behavior.
When autoescaping, the returned string object has a
twig_markup
value of true, which is unexpected and currently breaks certain usages of the twig module. For instance, you cannot insert thisString
as-is to your DOM, and must first call.valueOf()
. I've changed the output to always return a properly formatted string, rather than thisString
object. This should not break any existing code, as you can still call.valueOf()
on this newly returned string.The more glaring problem however, is that the current version of twig.js doubly-escapes strings marked as
html_attr
with thehtml
strategy. PHP Twig does not do this. I've added a fix for this.Here's a quick demo of the problem. Given this template
I've written the following test scripts in Node,
and in PHP.
The Node script output is as follows
while the PHP script outputs
Note that the inverse operation (i.e. escaping as 'html' while using 'html_attr') does double escape in both twig.js and PHP twig.