RPTools / maptool

Virtual Tabletop for playing roleplaying games with remote players or face to face.
http://rptools.net
GNU Affero General Public License v3.0
787 stars 259 forks source link

[Feature]: There should be a base64Encode handlebars helper to make it easier to safely programmatically handle token properties #4924

Closed fishface60 closed 2 days ago

fishface60 commented 1 week ago

Describe the Problem

Handling json property values in handlebars templates is awkward.

There's no helper for turning a property into json and using that as the context for another helper, and implementing one looks complicated, so I have been embedding the json into <script> elements and loading them from code.

Because it's possible for json data to contain </script> this should be escaped.

The standard handlebars option is to html-escape values so </script> becomes &lt;/script&gt; but for script tags .innerText doesn't translate from the html-escaped form to plain text. It is possible to create an ephemeral text element, set its content with .innerHTML and get the text out with .innerText but this is cumbersome, and substituting the script element for a hidden text element is horrible.

The Solution you'd like

In the absence of a helper to handle json properties directly, a base64Encode helper so that I can just use atob to decode it.

Alternatives that you've considered.

Additional Context

No response