Skip to content

fix(http): handle empty values and multi-line comments in ServerSentEventStream#7051

Open
tomas-zijdemans wants to merge 1 commit intodenoland:mainfrom
tomas-zijdemans:fix-sse
Open

fix(http): handle empty values and multi-line comments in ServerSentEventStream#7051
tomas-zijdemans wants to merge 1 commit intodenoland:mainfrom
tomas-zijdemans:fix-sse

Conversation

@tomas-zijdemans
Copy link
Contributor

@tomas-zijdemans tomas-zijdemans commented Mar 15, 2026

Bug 1: Empty values silently dropped. Fields like { data: "" } or { id: 0 } produced no output because the code used truthy checks (if (message.data)), which treat "" and 0 as false. Fixed by checking !== undefined instead.

Bug 2: Multi-line comments threw an error. The serializer rejected comments containing newlines with a SyntaxError, but comments are per-line constructs in SSE. This already worked correctly for data, just not for comments. Fixed by splitting on newlines instead of throwing.

See ServerSentEventParseStream for a roundtrip example (that requires this fix to work correctly)

Note: id?: string | number; in the ServerSentEventMessageinterface is a spec violation (it should only be string). I didn't change it, since that would be a breaking change. @kt3k: please let me know if you'd like me to include that as well.

Spec: https://html.spec.whatwg.org/multipage/server-sent-events.html#parsing-an-event-stream

@tomas-zijdemans tomas-zijdemans requested a review from kt3k as a code owner March 15, 2026 19:37
@github-actions github-actions bot added the http label Mar 15, 2026
@codecov
Copy link

codecov bot commented Mar 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.36%. Comparing base (6df7f21) to head (0a5d68d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7051      +/-   ##
==========================================
+ Coverage   94.01%   94.36%   +0.34%     
==========================================
  Files         627      627              
  Lines       50029    50031       +2     
  Branches     8807     8808       +1     
==========================================
+ Hits        47037    47212     +175     
+ Misses       2413     2251     -162     
+ Partials      579      568      -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant