Merge pull request #613 from greatcare/611-search-request-space-in-dn

Remove spaces from DNs in SearchRequest
This commit is contained in:
James Sumners 2020-05-15 17:41:04 -04:00 committed by GitHub
commit e14cf696a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -105,7 +105,13 @@ SearchRequest.prototype._parse = function (ber) {
SearchRequest.prototype._toBer = function (ber) {
assert.ok(ber)
ber.writeString(this.baseObject.toString())
// Format only with commas, since that is what RFC 4514 mandates.
// There's a gotcha here: even though it's called baseObject,
// it can be a string or a DN object.
var formattedDN = dn.DN.isDN(this.baseObject)
? this.baseObject.format({ skipSpace: true })
: this.baseObject.toString()
ber.writeString(formattedDN)
ber.writeEnumeration(this._scope)
ber.writeEnumeration(this.derefAliases)
ber.writeInt(this.sizeLimit)

View File

@ -78,7 +78,8 @@ test('toBer', function (t) {
t.equal(ber.readSequence(), 0x30)
t.equal(ber.readInt(), 123)
t.equal(ber.readSequence(), 0x63)
t.equal(ber.readString(), 'cn=foo, o=test')
// Make sure we've removed spaces from between RDNs:
t.equal(ber.readString(), 'cn=foo,o=test')
t.equal(ber.readEnumeration(), 1)
t.equal(ber.readEnumeration(), 2)
t.equal(ber.readInt(), 10)