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

Commit f6e2432

Browse files
authored
Merge pull request #1 from ldapjs/tostring-unescaped
Add unescaped option to toString
2 parents 2a12b73 + 57f54c7 commit f6e2432

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/rdn.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,20 @@ class RDN {
145145
* rnd.toString()
146146
* // => 'cn=\23foo+1.3.6.1.4.1.1466.0=#04024869'
147147
*
148+
* @example Unescaped Value
149+
* const rdn = new RDN({
150+
* cn: '#foo'
151+
* })
152+
* rdn.toString({ unescaped: true })
153+
* // => 'cn=#foo'
154+
*
155+
* @param {object} [options]
156+
* @param {boolean} [options.unescaped=false] Return the unescaped version
157+
* of the RDN string.
158+
*
148159
* @returns {string}
149160
*/
150-
toString () {
161+
toString ({ unescaped = false } = {}) {
151162
let result = ''
152163
const isHexEncodedValue = val => /^#([0-9a-fA-F]{2})+$/.test(val) === true
153164

@@ -163,7 +174,7 @@ class RDN {
163174
}
164175
result += encoded
165176
} else {
166-
result += escapeValue(entry.value)
177+
result += unescaped === false ? escapeValue(entry.value) : entry.value
167178
}
168179

169180
result += '+'

lib/rdn.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ tap.test('toString', t => {
132132
t.equal(rdn.toString(), 'cn=#0403666f6f')
133133
})
134134

135+
t.test('honors unescaped options', async t => {
136+
const rdn = new RDN({
137+
ou: '研发二组'
138+
})
139+
t.equal(rdn.toString({ unescaped: true }), 'ou=研发二组')
140+
})
141+
135142
t.end()
136143
})
137144

0 commit comments

Comments
 (0)