adobe/htl-spec

@ context is not escaping single quotes

Closed this issue · 2 comments

This code example where properties.titleLeft = GET 50% OFF ANY M'EDIUM OR L"AR"GE PIZZA!

<a href="#" onclick="trackPromoCta('${properties.titleLeft @ context='html'}')">Text</a>
<a href="#" onclick="trackPromoCta('${properties.titleLeft @ context='attribute'}')">Text</a>
<a href="#" onclick="trackPromoCta('${properties.titleLeft @ context='text'}')">Text</a>

Produces

<a href="#" onclick="trackPromoCta('Get 50% off any m'edium or l&quot;ar&quot;ge pizza!')">Text</a>

The single quote is not encoded as an HTML entity, therefore this function causes an error on button click as it ends too soon at the single quote in the what should be escaped content.

Producing error Uncaught SyntaxError: missing ) after argument list

This appears to be an engine specific issue rather than a problem with the spec. You may want to move your issue to https://github.com/apache/sling-org-apache-sling-scripting-sightly if that is the engine you are using.

The correct context for your expression is scriptString:

<a href="#" onclick="trackPromoCta('${properties.titleLeft @ context='scriptString'}')">Text</a>