Skip to content

Commit 48289f4

Browse files
Releasing version 1.4.1
1 parent daab314 commit 48289f4

File tree

3 files changed

+62
-25
lines changed

3 files changed

+62
-25
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

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

5+
## [1.4.1] - 2021-05-10
6+
### Fixed:
7+
- Updated the dependency on the package `original` in order to pick up a newer version of the transitive dependency `url-parse`. Older versions of `url-parse` had a [known vulnerability](https://github.com/advisories/GHSA-9m6j-fcg5-2442). (Thanks, [m-schrepel](https://github.com/launchdarkly/js-eventsource/pull/11)!)
8+
59
## [1.4.0] - 2021-01-25
610
### Added:
711
- Added `readTimeoutMillis` option for automatically dropping and restarting a connection if too much time has elapsed without receiving any data.

example/eventsource-polyfill.js

+57-24
Original file line numberDiff line numberDiff line change
@@ -3672,33 +3672,54 @@ function unwrapListeners(arr) {
36723672

36733673
function once(emitter, name) {
36743674
return new Promise(function (resolve, reject) {
3675-
function eventListener() {
3676-
if (errorListener !== undefined) {
3675+
function errorListener(err) {
3676+
emitter.removeListener(name, resolver);
3677+
reject(err);
3678+
}
3679+
3680+
function resolver() {
3681+
if (typeof emitter.removeListener === 'function') {
36773682
emitter.removeListener('error', errorListener);
36783683
}
36793684
resolve([].slice.call(arguments));
36803685
};
3681-
var errorListener;
3682-
3683-
// Adding an error listener is not optional because
3684-
// if an error is thrown on an event emitter we cannot
3685-
// guarantee that the actual event we are waiting will
3686-
// be fired. The result could be a silent way to create
3687-
// memory or file descriptor leaks, which is something
3688-
// we should avoid.
3689-
if (name !== 'error') {
3690-
errorListener = function errorListener(err) {
3691-
emitter.removeListener(name, eventListener);
3692-
reject(err);
3693-
};
36943686

3695-
emitter.once('error', errorListener);
3687+
eventTargetAgnosticAddListener(emitter, name, resolver, { once: true });
3688+
if (name !== 'error') {
3689+
addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true });
36963690
}
3697-
3698-
emitter.once(name, eventListener);
36993691
});
37003692
}
37013693

3694+
function addErrorHandlerIfEventEmitter(emitter, handler, flags) {
3695+
if (typeof emitter.on === 'function') {
3696+
eventTargetAgnosticAddListener(emitter, 'error', handler, flags);
3697+
}
3698+
}
3699+
3700+
function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
3701+
if (typeof emitter.on === 'function') {
3702+
if (flags.once) {
3703+
emitter.once(name, listener);
3704+
} else {
3705+
emitter.on(name, listener);
3706+
}
3707+
} else if (typeof emitter.addEventListener === 'function') {
3708+
// EventTarget does not have `error` event semantics like Node
3709+
// EventEmitters, we do not listen for `error` events here.
3710+
emitter.addEventListener(name, function wrapListener(arg) {
3711+
// IE does not have builtin `{ once: true }` support so we
3712+
// have to do it manually.
3713+
if (flags.once) {
3714+
emitter.removeEventListener(name, wrapListener);
3715+
}
3716+
listener(arg);
3717+
});
3718+
} else {
3719+
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter);
3720+
}
3721+
}
3722+
37023723

37033724
/***/ }),
37043725
/* 10 */
@@ -7379,8 +7400,8 @@ module.exports = origin;
73797400

73807401
var required = __webpack_require__(28)
73817402
, qs = __webpack_require__(29)
7382-
, slashes = /^[A-Za-z][A-Za-z0-9+-.]*:\/\//
7383-
, protocolre = /^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i
7403+
, slashes = /^[A-Za-z][A-Za-z0-9+-.]*:[\\/]+/
7404+
, protocolre = /^([a-z][a-z0-9.+-]*:)?([\\/]{1,})?([\S\s]*)/i
73847405
, whitespace = '[\\x09\\x0A\\x0B\\x0C\\x0D\\x20\\xA0\\u1680\\u180E\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200A\\u202F\\u205F\\u3000\\u2028\\u2029\\uFEFF]'
73857406
, left = new RegExp('^'+ whitespace +'+');
73867407

@@ -7492,12 +7513,16 @@ function lolcation(loc) {
74927513
*/
74937514
function extractProtocol(address) {
74947515
address = trimLeft(address);
7495-
var match = protocolre.exec(address);
7516+
7517+
var match = protocolre.exec(address)
7518+
, protocol = match[1] ? match[1].toLowerCase() : ''
7519+
, slashes = !!(match[2] && match[2].length >= 2)
7520+
, rest = match[2] && match[2].length === 1 ? '/' + match[3] : match[3];
74967521

74977522
return {
7498-
protocol: match[1] ? match[1].toLowerCase() : '',
7499-
slashes: !!match[2],
7500-
rest: match[3]
7523+
protocol: protocol,
7524+
slashes: slashes,
7525+
rest: rest
75017526
};
75027527
}
75037528

@@ -7657,6 +7682,14 @@ function Url(address, location, parser) {
76577682
url.pathname = resolve(url.pathname, location.pathname);
76587683
}
76597684

7685+
//
7686+
// Default to a / for pathname if none exists. This normalizes the URL
7687+
// to always have a /
7688+
//
7689+
if (url.pathname.charAt(0) !== '/' && url.hostname) {
7690+
url.pathname = '/' + url.pathname;
7691+
}
7692+
76607693
//
76617694
// We should not add port numbers if they are already the default port number
76627695
// for a given protocol. As the host also contains the port number we're going

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.0",
3+
"version": "1.4.1",
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)