From 9ed87238661720c0a4bd58dd9c5fc4d53e7b96ae Mon Sep 17 00:00:00 2001 From: LaunchDarklyReleaseBot Date: Mon, 10 Jan 2022 19:43:05 +0000 Subject: [PATCH] Releasing version 1.4.3 --- CHANGELOG.md | 8 ++++++++ example/eventsource-polyfill.js | 17 +++++++++++++---- package.json | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74f9039..d102a7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to this package will be documented in this file. +## [1.4.3] - 2022-01-10 +This release fixes a number of SSE spec compliance issues which do not affect usage in the LaunchDarkly SDKs, but could be relevant in other use cases. + +### Fixed: +- If an event's `id:` field contains a null character, the whole field should be ignored. +- The parser was incorrectly ignoring lines that did not contain a colon, instead of treating them as a field with an empty value. For instance, `data` on a line by itself should be equivalent to `data:`. +- The parser should ignore any incomplete messages at the end of a stream if the stream disconnects. + ## [1.4.2] - 2022-01-04 ### Fixed: - If the stream URL contained user/password basicauth fields, they were not being included in the request. diff --git a/example/eventsource-polyfill.js b/example/eventsource-polyfill.js index bcd4756..d20f6f7 100644 --- a/example/eventsource-polyfill.js +++ b/example/eventsource-polyfill.js @@ -6557,8 +6557,7 @@ function EventSource (url, eventSourceInitDict) { } var discardTrailingNewline = false - var data = '' - var eventName = '' + var data, eventName, eventId var reconnectUrl = null var retryDelayStrategy = new retryDelay.RetryDelayStrategy( @@ -6707,6 +6706,10 @@ function EventSource (url, eventSourceInitDict) { return } + data = '' + eventName = '' + eventId = undefined + readyState = EventSource.OPEN res.on('close', function () { res.removeAllListeners('close') @@ -6836,16 +6839,20 @@ function EventSource (url, eventSourceInitDict) { if (lineLength === 0) { if (data.length > 0) { var type = eventName || 'message' + if (eventId !== undefined) { + lastEventId = eventId + } var event = new MessageEvent(type, { data: data.slice(0, -1), // remove trailing newline lastEventId: lastEventId, origin: original(url) }) data = '' + eventId = undefined receivedEvent(event) } eventName = void 0 - } else if (fieldLength > 0) { + } else { var noValue = fieldLength < 0 var step = 0 var field = buf.slice(pos, pos + (noValue ? lineLength : fieldLength)).toString() @@ -6867,7 +6874,9 @@ function EventSource (url, eventSourceInitDict) { } else if (field === 'event') { eventName = value } else if (field === 'id') { - lastEventId = value + if (!value.includes("\u0000")) { + eventId = value + } } else if (field === 'retry') { var retry = parseInt(value, 10) if (!Number.isNaN(retry)) { diff --git a/package.json b/package.json index 8dbce1c..ec89119 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "launchdarkly-eventsource", - "version": "1.4.2", + "version": "1.4.3", "description": "Fork of eventsource package - W3C compliant EventSource client for Node.js and browser (polyfill)", "keywords": [ "eventsource",