GH-53 unable to parse !filters

This commit is contained in:
Mark Cavage 2012-01-24 08:56:30 -08:00
parent c727ac922f
commit 0e30dc50c4
4 changed files with 32 additions and 13 deletions

View File

@ -23,7 +23,7 @@ RESTDOWN = ./node_modules/.restdown/bin/restdown \
-m ${DOCPKGDIR} \
-D mediaroot=media
.PHONY: dep lint test doc clean all
.PHONY: dep lint test doc clean all install
all:: test doc
@ -38,6 +38,7 @@ node_modules/.ldapjs.npm.installed:
@touch ./node_modules/.ldapjs.npm.installed
dep: ./node_modules/.ldapjs.npm.installed
install: dep
gjslint:
gjslint --nojsdoc -r lib -r tst

View File

@ -12,16 +12,18 @@ var Protocol = require('../protocol');
///--- API
function NotFilter(options) {
if (typeof(options) !== 'object')
throw new TypeError('options (object) required');
if (!options.filter || !(options.filter instanceof Filter))
throw new TypeError('options.filter (Filter) required');
if (typeof(options) === 'object') {
if (!options.filter || !(options.filter instanceof Filter))
throw new TypeError('options.filter (Filter) required');
} else {
options = {};
}
this.filter = options.filter || {};
options.type = Protocol.FILTER_NOT;
Filter.call(this, options);
this.filter = options.filter;
var self = this;
this.__defineGetter__('json', function() {
return {
@ -34,6 +36,12 @@ util.inherits(NotFilter, Filter);
module.exports = NotFilter;
NotFilter.prototype.addFilter = function(f) {
if (!(f instanceof Filter))
throw new TypeError('filter (Filter) required');
this.filter = f;
};
NotFilter.prototype.toString = function() {
return '(!' + this.filter.toString() + ')';
};

View File

@ -26,12 +26,7 @@ test('load library', function(t) {
test('Construct no args', function(t) {
try {
new NotFilter();
t.fail('should have thrown');
} catch (e) {
t.ok(e instanceof TypeError);
}
t.ok(new NotFilter());
t.end();
});

View File

@ -79,3 +79,18 @@ test('* substr filter (prefix)', function(t) {
t.equal(f.initial, 'bar');
t.end();
});
test('GH-53 NotFilter', function(t) {
var str = '(&(objectClass=person)(!(objectClass=shadowAccount)))';
var f = parse(str);
t.ok(f);
t.equal(f.type, 'and');
t.equal(f.filters.length, 2);
t.equal(f.filters[0].type, 'equal');
t.equal(f.filters[1].type, 'not');
t.equal(f.filters[1].filter.type, 'equal');
t.equal(f.filters[1].filter.attribute, 'objectClass');
t.equal(f.filters[1].filter.value, 'shadowAccount');
t.end();
});