SubstringFilter can match against an array.
This commit is contained in:
parent
1b40436e34
commit
ef043af1d4
|
@ -56,3 +56,19 @@ Filter.prototype.toBer = function(ber) {
|
|||
ber.endSequence();
|
||||
return ber;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Test a rule against one or more values.
|
||||
*/
|
||||
Filter.multi_test = function (rule, value) {
|
||||
if(Array.isArray(value)) {
|
||||
var response = false;
|
||||
value.forEach(function(v) {
|
||||
if(rule(v)) { response = true; }
|
||||
});
|
||||
return response;
|
||||
} else {
|
||||
return rule(value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ SubstringFilter.prototype.matches = function(target) {
|
|||
re += this['final'] + '$';
|
||||
|
||||
var matcher = new RegExp(re);
|
||||
return matcher.test(target[this.attribute]);
|
||||
return Filter.multi_test( function(v) { return matcher.test(v); }, target[this.attribute]);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -78,6 +78,16 @@ test('match false', function(t) {
|
|||
});
|
||||
|
||||
|
||||
test('match any', function(t) {
|
||||
var f = new SubstringFilter({
|
||||
attribute: 'foo',
|
||||
initial: 'bar'
|
||||
});
|
||||
t.ok(f);
|
||||
t.ok(f.matches({ foo: ['beuha', 'barista']}));
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('parse ok', function(t) {
|
||||
var writer = new BerWriter();
|
||||
writer.writeString('foo');
|
||||
|
|
Loading…
Reference in New Issue