SubstringFilter can match against an array.

This commit is contained in:
Mathieu Lecarme 2011-12-04 22:32:22 +01:00
parent 1b40436e34
commit ef043af1d4
3 changed files with 27 additions and 1 deletions

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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');