From 4cf4291c5b590c45399003a89b4fa29143eecd5a Mon Sep 17 00:00:00 2001 From: Mathieu Lecarme Date: Mon, 5 Dec 2011 21:14:55 +0100 Subject: [PATCH 1/3] Testing each filters with multiple values. --- tst/filters/eq.test.js | 11 +++++++++++ tst/filters/ge.test.js | 10 ++++++++++ tst/filters/le.test.js | 11 +++++++++++ 3 files changed, 32 insertions(+) diff --git a/tst/filters/eq.test.js b/tst/filters/eq.test.js index 7d963ed..0da92f9 100644 --- a/tst/filters/eq.test.js +++ b/tst/filters/eq.test.js @@ -57,6 +57,17 @@ test('match true', function(t) { }); +test('match multiple', function(t) { + var f = new EqualityFilter({ + attribute: 'foo', + value: 'bar' + }); + t.ok(f); + t.ok(f.matches({ foo: ['plop', 'bar'] })); + t.end(); +}); + + test('match false', function(t) { var f = new EqualityFilter({ attribute: 'foo', diff --git a/tst/filters/ge.test.js b/tst/filters/ge.test.js index 52b6cb2..604ad14 100644 --- a/tst/filters/ge.test.js +++ b/tst/filters/ge.test.js @@ -57,6 +57,16 @@ test('match true', function(t) { }); +test('match multiple', function(t) { + var f = new GreaterThanEqualsFilter({ + attribute: 'foo', + value: 'bar' + }); + t.ok(f); + t.ok(f.matches({ foo: ['beuha', 'baz'] })); + t.end(); +}); + test('match false', function(t) { var f = new GreaterThanEqualsFilter({ attribute: 'foo', diff --git a/tst/filters/le.test.js b/tst/filters/le.test.js index 21380b4..545cdc3 100644 --- a/tst/filters/le.test.js +++ b/tst/filters/le.test.js @@ -57,6 +57,17 @@ test('match true', function(t) { }); +test('match multiple', function(t) { + var f = new LessThanEqualsFilter({ + attribute: 'foo', + value: 'bar' + }); + t.ok(f); + t.ok(f.matches({ foo: ['abc', 'beuha'] })); + t.end(); +}); + + test('match false', function(t) { var f = new LessThanEqualsFilter({ attribute: 'foo', From 7b5bef86d50d33de6989eefb360987c182debbf3 Mon Sep 17 00:00:00 2001 From: Mark Cavage Date: Tue, 6 Dec 2011 13:56:20 -0800 Subject: [PATCH 2/3] Control parsing incorrect if criticality field ommitted --- lib/control.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/control.js b/lib/control.js index a7c2688..778b847 100644 --- a/lib/control.js +++ b/lib/control.js @@ -63,8 +63,10 @@ Control.prototype.parse = function(ber) { if (ber.length) { this.type = ber.readString(); - if (ber.offset < end) - this.criticality = ber.readBoolean(); + if (ber.offset < end) { + if (ber.peek() === 0x01) // Boolean, optional + this.criticality = ber.readBoolean(); + } if (ber.offset < end) this.value = ber.readString(); From eadf70e99490284e1c3f0545d3583c0621d4e3d1 Mon Sep 17 00:00:00 2001 From: Mathieu Lecarme Date: Wed, 7 Dec 2011 21:22:34 +0100 Subject: [PATCH 3/3] Filter: filter against one or multiple values. --- lib/filters/equality_filter.js | 16 +++++----------- lib/filters/ge_filter.js | 17 +++++------------ lib/filters/le_filter.js | 17 +++++------------ 3 files changed, 15 insertions(+), 35 deletions(-) diff --git a/lib/filters/equality_filter.js b/lib/filters/equality_filter.js index f8999fd..5a1fa7e 100644 --- a/lib/filters/equality_filter.js +++ b/lib/filters/equality_filter.js @@ -47,20 +47,14 @@ EqualityFilter.prototype.matches = function(target) { if (typeof(target) !== 'object') throw new TypeError('target (object) required'); - var matches = false; if (target.hasOwnProperty(this.attribute)) { - if (Array.isArray(target[this.attribute])) { - for (var i = 0; i < target[this.attribute].length; i++) { - matches = (this.value === target[this.attribute][i]); - if (matches) - break; - } - } else { - matches = (this.value === target[this.attribute]); - } + var value = this.value; + return Filter.multi_test( + function(v) { return value === v; }, + target[this.attribute]); } - return matches; + return false; }; diff --git a/lib/filters/ge_filter.js b/lib/filters/ge_filter.js index 9177c4c..a2aa7d4 100644 --- a/lib/filters/ge_filter.js +++ b/lib/filters/ge_filter.js @@ -48,21 +48,14 @@ GreaterThanEqualsFilter.prototype.matches = function(target) { if (typeof(target) !== 'object') throw new TypeError('target (object) required'); - var matches = false; - if (target.hasOwnProperty(this.attribute)) { - if (Array.isArray(target[this.attribute])) { - for (var i = 0; i < target[this.attribute].length; i++) { - matches = (this.value <= target[this.attribute][i]); - if (matches) - break; - } - } else { - matches = (this.value <= target[this.attribute]); - } + var value = this.value; + return Filter.multi_test( + function(v) { return value <= v; }, + target[this.attribute]); } - return matches; + return false; }; diff --git a/lib/filters/le_filter.js b/lib/filters/le_filter.js index eb87149..e90fa03 100644 --- a/lib/filters/le_filter.js +++ b/lib/filters/le_filter.js @@ -48,21 +48,14 @@ LessThanEqualsFilter.prototype.matches = function(target) { if (typeof(target) !== 'object') throw new TypeError('target (object) required'); - var matches = false; if (target.hasOwnProperty(this.attribute)) { - if (Array.isArray(target[this.attribute])) { - for (var i = 0; i < target[this.attribute].length; i++) { - matches = (this.value >= target[this.attribute][i]); - if (matches) - break; - } - } else { - matches = (this.value >= target[this.attribute]); - } + var value = this.value; + return Filter.multi_test( + function(v) { return value >= v; }, + target[this.attribute]); } - - return matches; + return false; };