Skip to content

Commit 9ed8723

Browse files
author
LaunchDarklyReleaseBot
committed
Releasing version 1.4.3
1 parent 9715f5d commit 9ed8723

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
All notable changes to this package will be documented in this file.
44

5+
## [1.4.3] - 2022-01-10
6+
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.
7+
8+
### Fixed:
9+
- If an event's `id:` field contains a null character, the whole field should be ignored.
10+
- 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:`.
11+
- The parser should ignore any incomplete messages at the end of a stream if the stream disconnects.
12+
513
## [1.4.2] - 2022-01-04
614
### Fixed:
715
- If the stream URL contained user/password basicauth fields, they were not being included in the request.

example/eventsource-polyfill.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -6557,8 +6557,7 @@ function EventSource (url, eventSourceInitDict) {
65576557
}
65586558

65596559
var discardTrailingNewline = false
6560-
var data = ''
6561-
var eventName = ''
6560+
var data, eventName, eventId
65626561

65636562
var reconnectUrl = null
65646563
var retryDelayStrategy = new retryDelay.RetryDelayStrategy(
@@ -6707,6 +6706,10 @@ function EventSource (url, eventSourceInitDict) {
67076706
return
67086707
}
67096708

6709+
data = ''
6710+
eventName = ''
6711+
eventId = undefined
6712+
67106713
readyState = EventSource.OPEN
67116714
res.on('close', function () {
67126715
res.removeAllListeners('close')
@@ -6836,16 +6839,20 @@ function EventSource (url, eventSourceInitDict) {
68366839
if (lineLength === 0) {
68376840
if (data.length > 0) {
68386841
var type = eventName || 'message'
6842+
if (eventId !== undefined) {
6843+
lastEventId = eventId
6844+
}
68396845
var event = new MessageEvent(type, {
68406846
data: data.slice(0, -1), // remove trailing newline
68416847
lastEventId: lastEventId,
68426848
origin: original(url)
68436849
})
68446850
data = ''
6851+
eventId = undefined
68456852
receivedEvent(event)
68466853
}
68476854
eventName = void 0
6848-
} else if (fieldLength > 0) {
6855+
} else {
68496856
var noValue = fieldLength < 0
68506857
var step = 0
68516858
var field = buf.slice(pos, pos + (noValue ? lineLength : fieldLength)).toString()
@@ -6867,7 +6874,9 @@ function EventSource (url, eventSourceInitDict) {
68676874
} else if (field === 'event') {
68686875
eventName = value
68696876
} else if (field === 'id') {
6870-
lastEventId = value
6877+
if (!value.includes("\u0000")) {
6878+
eventId = value
6879+
}
68716880
} else if (field === 'retry') {
68726881
var retry = parseInt(value, 10)
68736882
if (!Number.isNaN(retry)) {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "launchdarkly-eventsource",
3-
"version": "1.4.2",
3+
"version": "1.4.3",
44
"description": "Fork of eventsource package - W3C compliant EventSource client for Node.js and browser (polyfill)",
55
"keywords": [
66
"eventsource",

0 commit comments

Comments
 (0)