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

improve current solution for serializing JSON in HTML #47

Open
thescientist13 opened this issue Oct 18, 2022 · 0 comments
Open

improve current solution for serializing JSON in HTML #47

thescientist13 opened this issue Oct 18, 2022 · 0 comments
Labels

Comments

@thescientist13
Copy link
Contributor

thescientist13 commented Oct 18, 2022

Currently in order to handle serializing JSON that might contain an apostrophe, like with #16 , it requires a two step process

So for example, using this example

{
  title: 'Tuesday\'s Tunes Season Premier!'
}
  1. Convert the ' to " and use ' for the HTML attributes
    <tt-upcoming-events events='${JSON.stringify(events).replace(/'/g, '\\"')}'></tt-upcoming-events>
  2. In the component, convert them back to '
    const formattedTitle = title.replace(/"/g, '\'');
  • If you double quote, everything stops at the first double quote, e.g. [{
  • If you single quote, it stops at the first single quote, e.g. [{"title":"Tuesday

It would be nice if there was a single way, whether using " or ' in the HTML to avoid escaping issues, such that it has to fixed on the component side too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

No branches or pull requests

1 participant