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

Single quotes not properly handled in Turbo Streams broadcast #588

Open
nquocvuong opened this issue Feb 19, 2024 · 0 comments
Open

Single quotes not properly handled in Turbo Streams broadcast #588

nquocvuong opened this issue Feb 19, 2024 · 0 comments

Comments

@nquocvuong
Copy link

I have a form in my Rails application that is updated via Turbo Streams. The form contains input fields, and when certain actions occur (e.g., form submission), I use Turbo Streams to broadcast updates and refresh the form on the client side.

However, I've encountered an inconsistency in the behavior of Turbo Streams when handling single quotes (') within the HTML content being broadcast. Specifically, it appears that single quotes within the HTML content are being improperly escaped or encoded, resulting in single quotes is doubled when the form is refreshed.

screenshot:

image

this is my broadcast code:

Turbo::StreamsChannel.broadcast_replace_to(
    :documents,
    target: dom_id(document),
    partial: 'documents/document', # form
    locals: {document: document}
  )

and this is the message receive on client-side ( by websocket)

"<turbo-stream action=\"replace\" target=\"=document_b94ce5f6-c3f4-4d08-a050-3724356fdba8\"><template><turbo-frame id=\"document_b94ce5f6-c3f4-4d08-a050-3724356fdba8\">
<form action=\"/documents/b94ce5f6-c3f4-4d08-a050-3724356fdba8\" accept-charset=\"UTF-8\" method=\"post\">
<input type=''submit'' hidden />
...
<div class=\"has-error\">
  <input class=\"form-control\" type=\"date\" name=\"document[document_date]\" id=\"document_document_date\" />
  <span class=\"help-block form-text\">can''t be blank</span>
 </div>
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant