10000 Add JS string escape helper · Issue #847 · yippee-fun/phlex · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add JS string escape helper #847

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

Closed
scottwhudson opened this issue Feb 8, 2025 · 3 comments · Fixed by #872
Closed
8000

Add JS string escape helper #847

scottwhudson opened this issue Feb 8, 2025 · 3 comments · Fixed by #872
Assignees

Comments

@scottwhudson
Copy link
scottwhudson commented Feb 8, 2025

Hey Joel 👋,

Thanks for the Phlex library, it feels like what HAML and view components could've been.

We're using it alongside alpine.js and overall very happy with the experience. One issue we're running into is the need to escape strings prior to JS evaluation and our current approach feels slightly cumbersome. I'd love to open a PR to add a JS string escape helper that leverages json_escape and raw under the hood to ensure that we're not exposing ourselves to XSS attacks.

Are you open to a contribution like this?

@joeldrapper
Copy link
Collaborator

Hey, that sounds like a good idea. Do you have an example of the approach you have in mind? Not the implementation but the interface. What would it look like with alpine?

@joeldrapper
Copy link
Collaborator

I don’t think we can find automatically escape JSON strings like we can with HTML, so I guess the interface would be just adding a json_escape helper.

def json_escape(string)
  ERB::Util.json_escape(string)
end

@joeldrapper joeldrapper added this to the 2.1 milestone Feb 12, 2025
@scottwhudson
Copy link
Author
9306

This is my feeling as well. We don't have a particularly elegant way of dynamically applying the JSON escape logic in the templates automagically without tying the implementation logic to the alpine-specific data attributes. I'll whip up a PR for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0