Skip to content

fix(eventsource): handle empty event fields#5584

Open
Ram-blip wants to merge 1 commit into
nodejs:mainfrom
Ram-blip:fix/eventsource-empty-event-field
Open

fix(eventsource): handle empty event fields#5584
Ram-blip wants to merge 1 commit into
nodejs:mainfrom
Ram-blip:fix/eventsource-empty-event-field

Conversation

@Ram-blip

Copy link
Copy Markdown
Contributor

This relates to...

This PR corrects EventSource behavior when an empty event field follows a previously specified custom event type in the same Server-Sent Events block.

Rationale

The Server-Sent Events specification requires every recognized event field to replace the current event-type buffer, including when the field value is empty.

For example:

event: custom
event:
data: payload

The second event field has an empty value, so it should clear the previous custom event type. The payload should then be dispatched using the default message event type.

Undici previously ignored empty event field values. As a result, the earlier custom value remained in the event-type buffer, and the payload was incorrectly dispatched to the custom listener instead of the default message listener.

Changes

Features

N/A

Bug Fixes

  • Process empty event field values instead of ignoring them.
  • Clear a previously specified custom event type when it is followed by an empty event field.
  • Restore dispatch to the default message event type when the event-type buffer is empty.
  • Add a parser regression test covering a custom event type followed by an empty event field.
  • Add a public EventSource regression test verifying that the payload is delivered to the message listener.

Breaking Changes and Deprecations

None.

This change only corrects the previous non-conformant listener-routing behavior for valid SSE blocks containing a nonempty event field followed by an empty one.

Status

Signed-off-by: Ram-blip <ramcruze2000@gmail.com>
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.

1 participant