From 3c5138de26e54d9c7dbcc16515b6df044668dfdb Mon Sep 17 00:00:00 2001 From: Robert Kawecki Date: Thu, 16 Jul 2020 14:32:04 +0200 Subject: [PATCH 1/5] Remove instanceof check in filter#toBer mixin For #629 --- lib/filters/filter.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/filters/filter.js b/lib/filters/filter.js index 4c7e4ba..612b7fd 100644 --- a/lib/filters/filter.js +++ b/lib/filters/filter.js @@ -2,14 +2,10 @@ // var assert = require('assert') -var asn1 = require('asn1') - var Protocol = require('../protocol') /// --- Globals -var BerWriter = asn1.BerWriter - var TYPES = { and: Protocol.FILTER_AND, or: Protocol.FILTER_OR, @@ -40,7 +36,7 @@ function isFilter (filter) { function mixin (target) { target.prototype.toBer = function toBer (ber) { - if (!ber || !(ber instanceof BerWriter)) { throw new TypeError('ber (BerWriter) required') } + if (!ber) { throw new TypeError('ber (BerWriter) required') } ber.startSequence(TYPES[this.type]) ber = this._toBer(ber) From b0b5e935c7f7d11fe84586a28ae61119e01b0ce4 Mon Sep 17 00:00:00 2001 From: Robert Kawecki Date: Thu, 16 Jul 2020 16:10:54 +0200 Subject: [PATCH 2/5] Add duck-type check for BerWriter in filter#toBer mixin For #629 --- lib/filters/filter.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/filters/filter.js b/lib/filters/filter.js index 612b7fd..f2e311b 100644 --- a/lib/filters/filter.js +++ b/lib/filters/filter.js @@ -34,9 +34,17 @@ function isFilter (filter) { return false } +function isBerWriter (ber) { + return ( + typeof (ber) === 'object' && + typeof (ber.startSequence) === 'function' && + typeof (ber.endSequence) === 'function' + ) +} + function mixin (target) { target.prototype.toBer = function toBer (ber) { - if (!ber) { throw new TypeError('ber (BerWriter) required') } + if (!ber || !isBerWriter(ber)) { throw new TypeError('ber (BerWriter) required') } ber.startSequence(TYPES[this.type]) ber = this._toBer(ber) From 4318b28198bbd365a72fcf7b3b066ede164f926c Mon Sep 17 00:00:00 2001 From: Robert Kawecki Date: Tue, 21 Jul 2020 13:34:59 +0200 Subject: [PATCH 3/5] Integrate falsy check into isBerWriter to avoid long inline conditions For #629 --- lib/filters/filter.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/filters/filter.js b/lib/filters/filter.js index f2e311b..fc4d061 100644 --- a/lib/filters/filter.js +++ b/lib/filters/filter.js @@ -35,7 +35,8 @@ function isFilter (filter) { } function isBerWriter (ber) { - return ( + return Boolean( + ber && typeof (ber) === 'object' && typeof (ber.startSequence) === 'function' && typeof (ber.endSequence) === 'function' @@ -44,7 +45,7 @@ function isBerWriter (ber) { function mixin (target) { target.prototype.toBer = function toBer (ber) { - if (!ber || !isBerWriter(ber)) { throw new TypeError('ber (BerWriter) required') } + if (!isBerWriter(ber)) { throw new TypeError('ber (BerWriter) required') } ber.startSequence(TYPES[this.type]) ber = this._toBer(ber) From 1a09e62eda19b73d4587c16c9b82d19d4631cd3c Mon Sep 17 00:00:00 2001 From: Robert Kawecki Date: Tue, 21 Jul 2020 13:51:49 +0200 Subject: [PATCH 4/5] Make false check explicit in isBerWriter comparison Co-authored-by: James Sumners --- lib/filters/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/filters/filter.js b/lib/filters/filter.js index fc4d061..3874a45 100644 --- a/lib/filters/filter.js +++ b/lib/filters/filter.js @@ -45,7 +45,7 @@ function isBerWriter (ber) { function mixin (target) { target.prototype.toBer = function toBer (ber) { - if (!isBerWriter(ber)) { throw new TypeError('ber (BerWriter) required') } + if (isBerWriter(ber) === false) { throw new TypeError('ber (BerWriter) required') } ber.startSequence(TYPES[this.type]) ber = this._toBer(ber) From b8100b114c5a4040e6ec06b2aa1f100b00c953d3 Mon Sep 17 00:00:00 2001 From: James Sumners Date: Tue, 21 Jul 2020 17:54:12 -0400 Subject: [PATCH 5/5] v2.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 468dc27..989198f 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "name": "ldapjs", "homepage": "http://ldapjs.org", "description": "LDAP client and server APIs", - "version": "2.0.0", + "version": "2.1.0", "license": "MIT", "repository": { "type": "git",