Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit 6b092cf

Browse files
committed
Remove spaces from DNs in SearchRequest
This change fixes how DNs are serialized into BER for SearchRequest messages. It drops spaces around commas, since it breaks some LDAP servers that expect the DN to be separated by comma only as per RFC 4514. The old format of spaced separators from LDAPv2 is thus no longer used. For #611
1 parent 5204bb7 commit 6b092cf

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/messages/search_request.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,13 @@ SearchRequest.prototype._parse = function (ber) {
105105
SearchRequest.prototype._toBer = function (ber) {
106106
assert.ok(ber)
107107

108-
ber.writeString(this.baseObject.toString())
108+
// Format only with commas, since that is what RFC 4514 mandates.
109+
// There's a gotcha here: even though it's called baseObject,
110+
// it can be a string or a DN object.
111+
var formattedDN = dn.DN.isDN(this.baseObject)
112+
? this.baseObject.format({ skipSpace: true })
113+
: this.baseObject.toString()
114+
ber.writeString(formattedDN)
109115
ber.writeEnumeration(this._scope)
110116
ber.writeEnumeration(this.derefAliases)
111117
ber.writeInt(this.sizeLimit)

test/messages/search_request.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ test('toBer', function (t) {
7878
t.equal(ber.readSequence(), 0x30)
7979
t.equal(ber.readInt(), 123)
8080
t.equal(ber.readSequence(), 0x63)
81-
t.equal(ber.readString(), 'cn=foo, o=test')
81+
// Make sure we've removed spaces from between RDNs:
82+
t.equal(ber.readString(), 'cn=foo,o=test')
8283
t.equal(ber.readEnumeration(), 1)
8384
t.equal(ber.readEnumeration(), 2)
8485
t.equal(ber.readInt(), 10)

0 commit comments

Comments
 (0)