diff --git a/lib/client.js b/lib/client.js index 2d6dc70..5d01af5 100644 --- a/lib/client.js +++ b/lib/client.js @@ -677,7 +677,7 @@ Client.prototype._newConnection = function() { if (self._bindDN && self._credentials) { // reconnect case self.bind(self._bindDN, self._credentials, [], function(err) { - if(err) { + if (err) { log.trace('%s error rebinding: %s', c.ldap.id, err.stack); return c.end(); } @@ -757,4 +757,4 @@ Client.prototype._newConnection = function() { }); return c; -} +}; diff --git a/lib/messages/search_response.js b/lib/messages/search_response.js index 7de79d3..3403a62 100644 --- a/lib/messages/search_response.js +++ b/lib/messages/search_response.js @@ -44,6 +44,8 @@ SearchResponse.prototype.send = function(entry, nofiltering) { throw new TypeError('entry (SearchEntry) required'); if (nofiltering === undefined) nofiltering = false; + if (typeof(nofiltering) !== 'boolean') + throw new TypeError('noFiltering must be a boolean'); var self = this; @@ -56,26 +58,21 @@ SearchResponse.prototype.send = function(entry, nofiltering) { if (!entry.attributes) throw new Error('entry.attributes required'); + var all = (self.attributes.indexOf('*') !== -1); + Object.keys(entry.attributes).forEach(function(a) { + var _a = a.toLowerCase(); + if (!nofiltering && _a.length && _a[0] === '_') { + delete entry.attributes[a]; + } else if (self.notAttributes.indexOf(_a) !== -1) { + delete entry.attributes[a]; + } else if (all) { + // noop + } else if (self.attributes.length && self.attributes.indexOf(_a) === -1) { + delete entry.attributes[a]; + } + }); + var save = entry; - - // Rip out anything that either the client didn't ask for, the server - // wants to strip, or 'private' vars that are prefixed with '_' - if (!nofiltering && - self.attributes && - self.attributes.length && - self.attributes.indexOf('*') === -1) { - - Object.keys(entry.attributes).forEach(function(a) { - var _a = a.toLowerCase(); - if (self.attributes.indexOf(_a) === -1 || - (self.notAttributes.length && - self.notAttributes.indexOf(_a) !== -1) || - (_a.length && _a.charAt(0) === '_')) { - delete entry.attributes[a]; - } - }); - } - entry = new SearchEntry({ objectName: typeof(save.dn) === 'string' ? parseDN(save.dn) : save.dn, messageID: self.messageID, @@ -94,10 +91,10 @@ SearchResponse.prototype.send = function(entry, nofiltering) { this.log.warn('%s failure to write message %j: %s', this.connection.ldap.id, this.json, e.toString()); } - }; + SearchResponse.prototype.createSearchEntry = function(object) { if (!object || typeof(object) !== 'object') throw new TypeError('object required'); diff --git a/package.json b/package.json index 697167c..4c8da7b 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "name": "ldapjs", "homepage": "http://ldapjs.org", "description": "LDAP client and server APIs", - "version": "0.2.0", + "version": "0.2.1", "repository": { "type": "git", "url": "git://github.com/mcavage/node-ldapjs.git" diff --git a/tst/client.test.js b/tst/client.test.js index 9ad00aa..77380a3 100644 --- a/tst/client.test.js +++ b/tst/client.test.js @@ -110,7 +110,7 @@ test('setup', function(t) { dn: 'dc=empty', attributes: { member: [], - 'member;range=0-1': ['cn=user1, dc=empty','cn=user2, dc=empty'] + 'member;range=0-1': ['cn=user1, dc=empty', 'cn=user2, dc=empty'] } }); res.end();