Skip to content

fix: preserve Unicode when splitting text frames - #753

Open
edsonsims wants to merge 1 commit into
stomp-js:developfrom
edsonsims:fix/preserve-unicode-text-chunks
Open

edsonsims wants to merge 1 commit into
stomp-js:developfrom
edsonsims:fix/preserve-unicode-text-chunks

Conversation

@edsonsims

Copy link
Copy Markdown

With splitLargeFrames: true, a substring boundary can separate a UTF-16 surrogate pair. Separate WebSocket text sends then replace the two lone surrogates, corrupting the STOMP body and its declared content length. An actual loopback reproduction at the default 8192-unit limit changes an 8143-byte body into 8145 received bytes.

I keep complete pairs in the same text chunk. A one-unit limit cannot represent a pair, so the complete serialized text frame is checked before sending and that case throws RangeError without a partial frame. A subsequent ASCII publish still works. Unsplit and binary paths retain their behavior. The option documentation now describes the existing UTF-16-unit limit; this does not implement a UTF-8 byte limit.

Validation:

  • The final 16 regressions fail 10 cases on the original source, with 6 passing controls; all 16 pass with the fix.
  • The full Node suite passes 159 tests against the repository's RabbitMQ fixture. Build and lint pass.
  • Both ws and native Node WebSocket loopback reproductions preserve the original bytes with the fix. An independent 19-case public-API probe passes for each transport, including tiny/default limits, header/body rejection, recovery and binary controls.

Tested on Node 24.19.0/macOS arm64. No Spring broker or broader platform compatibility result is claimed. Changed docs/tests/changelog pass formatting; one unrelated original spacing finding remains in the handler.

@kum-deepak

Copy link
Copy Markdown
Member

Many thanks for the PR.

Did you observe an issue while using the library?

A longer explanation: splitting a large text frame is a non-standard feature, supported only by the Java Spring broker. This feature may have been relevant when WebSocket implementations were not up to the mark. The current WebSocket standard and implementations support fragmenting large text messages transparently. So, this flag is probably unnecessary, and I had planned to drop it in the next major version.

So, it is important for me to understand why you needed to use this flag.

This branch has not been deployed

No deployments
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 this pull request may close these issues.

2 participants