Skip to content

[ISSUE #6752] fix: encode SSE events as UTF-8 - #6930

Open
yykaue wants to merge 8 commits into
apache:masterfrom
yykaue:fix-6752-sse-utf8-encoding
Open

[ISSUE #6752] fix: encode SSE events as UTF-8#6930
yykaue wants to merge 8 commits into
apache:masterfrom
yykaue:fix-6752-sse-utf8-encoding

Conversation

@yykaue

@yykaue yykaue commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #6752.

SseEventFormatter previously used the platform-default charset when converting SSE events and comments to bytes. On systems where the default charset is not UTF-8, non-ASCII MCP payloads could be corrupted.

Since Server-Sent Events are UTF-8 text streams, this PR:

  • Uses StandardCharsets.UTF_8 when encoding SSE events.
  • Uses StandardCharsets.UTF_8 when encoding SSE comments.
  • Adds byte-level regression tests covering non-ASCII JSON event data and comments.

Verification

  • The regression tests fail before the fix when executed with an ISO-8859-1 default charset.
  • The same tests pass after the fix in a non-UTF-8 environment.
  • Relevant tests, compilation, and Checkstyle pass.

@Aias00 Could you please review this PR?

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #6930 Review — [ISSUE #6752] fix: encode SSE events as UTF-8

Verdict: APPROVE

Scope

SseEventFormatter.formatEvent / formatComment (shenyu-plugin-mcp-server): encode SSE
payloads with StandardCharsets.UTF_8 instead of the platform-default charset.

Verification

  • Two production lines changed (getBytes()getBytes(StandardCharsets.UTF_8)); import java.nio.charset.StandardCharsets added. SSE is a UTF-8 text stream, so this is the correct
    encoding and removes a real corruption risk on ISO-8859-1 default-charset systems.
  • Regression test SseEventFormatterTest added: byte-level assertArrayEquals for a non-ASCII
    JSON event (你好,世界) and a non-ASCII comment (保持连接), compared against the expected
    UTF-8 bytes. Directly reproduces the bug (fails under ISO-8859-1) and is fixed by the change.
  • No API/signature change; mock-reactive MockServerWebExchange already on classpath.

Notes

  • Minimal, correct, well-tested. Approving.

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.

[BUG] SseEventFormatter uses default-charset getBytes() for SSE

2 participants