Skip to content

Single quotes not properly handled in Turbo Streams broadcast #588

Open
@nquocvuong

Description

@nquocvuong

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>
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions