This repository was archived by the owner on May 14, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff 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 - 9 a - f A - 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 += '+'
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments