fix(http): handle empty values and multi-line comments in ServerSentEventStream#7051
Open
tomas-zijdemans wants to merge 1 commit intodenoland:mainfrom
Open
fix(http): handle empty values and multi-line comments in ServerSentEventStream#7051tomas-zijdemans wants to merge 1 commit intodenoland:mainfrom
ServerSentEventStream#7051tomas-zijdemans wants to merge 1 commit intodenoland:mainfrom
Conversation
b18039f to
0a5d68d
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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""and0as false. Fixed by checking!== undefinedinstead.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
ServerSentEventParseStreamfor a roundtrip example (that requires this fix to work correctly)Note:
id?: string | number;in theServerSentEventMessageinterface is a spec violation (it should only bestring). 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