GH-16: dn.equals broken on empty strings
This commit is contained in:
parent
d2d99d14a6
commit
be3d5fa7fa
19
lib/dn.js
19
lib/dn.js
|
@ -268,14 +268,19 @@ DN.prototype.equals = function(dn) {
|
|||
for (var i = 0; i < this.rdns.length; i++) {
|
||||
var ours = this.rdns[i];
|
||||
var theirs = dn.rdns[i];
|
||||
for (var k in ours) {
|
||||
if (ours.hasOwnProperty(k)) {
|
||||
if (!theirs.hasOwnProperty(k))
|
||||
return false;
|
||||
var ourKeys = Object.keys(ours);
|
||||
var theirKeys = Object.keys(theirs);
|
||||
if (ourKeys.length !== theirKeys.length)
|
||||
return false;
|
||||
|
||||
if (ours[k] !== theirs[k])
|
||||
return false;
|
||||
}
|
||||
ourKeys.sort();
|
||||
theirKeys.sort();
|
||||
|
||||
for (var j = 0; j < ourKeys.length; j++) {
|
||||
if (ourKeys[j] !== theirKeys[j])
|
||||
return false;
|
||||
if (ours[ourKeys[j]] !== theirs[ourKeys[j]])
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -110,3 +110,16 @@ test('parent of', function(t) {
|
|||
t.ok(dn1.parentOf(dn.parse('cn=moo, cn=foo, dc=bar')));
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
||||
test('empty DNs GH-16', function(t) {
|
||||
var _dn = dn.parse('');
|
||||
var _dn2 = dn.parse('cn=foo');
|
||||
t.notOk(_dn.equals('cn=foo'));
|
||||
t.notOk(_dn2.equals(''));
|
||||
t.notOk(_dn.parentOf('cn=foo'));
|
||||
t.notOk(_dn.childOf('cn=foo'));
|
||||
t.notOk(_dn2.parentOf(''));
|
||||
t.notOk(_dn2.childOf(''));
|
||||
t.end();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue