Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fishface60 opened this issue Sep 15, 2024 · 0 comments · May be fixed by #4925
Labels
feature Adding functionality that adds value

Comments

@fishface60
Copy link
Contributor

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.

  • Trust that tokens aren't going to get invalid data in and it's safe to inline them into the script directly.
  • Use an ephemeral element to html-decode.
  • Use a hidden text element so .innerText works as expected.
  • Learn how to have a json parse helper.

Additional Context

No response

@fishface60 fishface60 added the feature Adding functionality that adds value label Sep 15, 2024
@fishface60 fishface60 linked a pull request Sep 15, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Adding functionality that adds value
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant