Using triple mustaches {{{ }}} can result in amp validator throwing error on unescaped template
Using triple mustaches {{{ }}} can result in amp validator throwing an error on unescaped template.
Code snippet below:
<amp-list width="auto"
height="800" layout="fixed-height"
src="/greetings">
<template type="amp-mustache">
<div>
<p on='tap:AMP.setState({
mainCat:"{{{greeting}}}"
})'>
</p>
</div>
</template>
</amp-list>
will throw an amp validation error:
The attribute 'on' in tag 'p' is set to 'tap:AMP.setState({ mainCat:"{{{greeting}}}" })', which contains unescaped Mustache template syntax.
Our data source has strings like ″ that needs to be converted to ″ by using {{{ }}}.
/to @Gregable @honeybadgerdontcare
@micyeung Can you elaborate on this comment:
Our data source has strings like ″ that needs to be converted to ″ by using {{{ }}}.
Triple mustache syntax is designed to prevent escaping by dropping the variable in as a raw string, so I don't understand why you think it would convert a value?
@aghassemi Can you confirm that amp-mustache even supports this subset of mustache syntax?
Would it have helped if I had used "rendered as" instead of "converted"? The use case here is that the data source was ″ and we were trying have that be rendered as ″.
I think part of the confusion is that it wasn't clear that there was anything to escape; binding ″ in {{{ }}} outside of template actually renders the ″ correctly and does not throw any validation error.
Also - This is actually not a high priority anymore (thank you for jumping in!), because the workaround in our case would just be to programmatically change the data source from ″ to just be ″, and then use {{ }} inside the template.
My understanding of this issue is that we're running into a case of escaping/unescaping muck.
The original data source string has various quotation marks in it (double quote in this case) which we want to pass through JSON and amp-bind. At each layer, these quotation marks need to be string escaped (using backslash) once, however some bug seems to be failing either string escaping or unescaping incorrectly. The workaround has been to use ″ (" would have also worked, same glyph) in the string as this html escaping doesn't interact with the string escaping in JSON and amp-bind.
However, amp-mustache expects to do all of the HTML escaping itself, not allowing the author to produce unescaped html. Therefore ″ gets html escaped to &Prime;, rather than the intended ".
The root issue is either a bug in the author's string escaping (likely) or amp-bind/json's string unescaping (less likely).
I've asked @micyeung to see if he can find a case where string escaping won't work, but in the meantime will close this issue.