GH-16: dn.equals broken on empty strings

This commit is contained in:
Mark Cavage 2011-09-23 08:54:48 -07:00
parent d2d99d14a6
commit be3d5fa7fa
2 changed files with 25 additions and 7 deletions

View File

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

View File

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