reclaim-the-stack / actioncable-enhanced-postgresql-adapter

An enhanced ActionCable adapter for PostgreSQL.
MIT License
116 stars 3 forks source link

Quotes / double escaping issue #4

Open abr-storm opened 1 month ago

abr-storm commented 1 month ago

Ruby: 3.4 preview Rails: Edge Postgresql: 17rc1

I'm running into an issue when my payload becomes large enough to trigger the special handling of this adapter. I'm rendering responses on the server side like this:

def broadcast
  html = ApplicationController.render(partial: "my/partial", layout: false)
  broadcast_action_later_to self, action: "replace", target: dom_id(self), html:
end

The page is updated with the correct markup when using the async adapter, or the enhanced_postgresql adapter when the response is small enough:

<div>
  <h1 class="font-bold text-xxl">Placeholder heading</h1>
</div>

But when the payload is large enough to trigger a read from action_cable_large_payloads, the markup looks like this:

<div>
  <h1 class="" font-bold="" text-xxl''="">Placeholder heading</h1>
</div>
martinmanyhats commented 1 month ago

Ruby: 3.3.1 Rails: 7.2.0 Postgresql: 14.13

Well that might explain why I've seen very similar symptoms ie attributes being mangled the same way. I ended up breaking the element to be replaced (which could get large) in to a number of much smaller fragments that are individually updated via a sequence of broadcast_replace_to. So I guess I managed to reduce each fragment to be under the magic size limit.

chriscz commented 1 month ago

There are a few ~unescaped~ incorrectly escaped exec calls in the source. In particular where the payload was inserted into the DB.

martinmanyhats commented 1 month ago

I've manually added the fix by chriscz and it resolved my issue with quotes being messed up for a larger payload.