fix: Reset event type after empty SSE block - #85
Open
lux-in-tenebris-lucet wants to merge 1 commit into
Open
Conversation
Reset the buffered event type whenever a blank line ends an SSE block, even if no data was collected. This prevents an empty named block from routing the next message to the wrong listener. Add dependency-free Node tests for named events and the regression.
lux-in-tenebris-lucet
marked this pull request as ready for review
July 30, 2026 12:45
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.
Summary
Problem
The parser currently resets its event type only when the completed block contains data.
For this valid event stream:
the empty
customblock leaves its event type buffered. The followinghelloevent is therefore sent to thecustomlistener instead of the defaultmessagelistener.The SSE parsing algorithm requires the event type buffer to be cleared when a block is dispatched, including when the block contains no data.
User impact
Applications using this stream pattern can silently miss messages because the expected
messagelistener is never called. The data may instead be delivered to an unrelated custom-event listener, potentially causing incorrect application behavior.This is an uncommon stream shape, but it is valid SSE and should be parsed correctly.
Fix
Move the parser-state reset outside the data check so that every blank-line block boundary clears the buffered data and event type.
Testing
npm test: 2 tests passed.Related to #14 by adding initial automated parser coverage.