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 {
145
145
* rnd.toString()
146
146
* // => 'cn=\23foo+1.3.6.1.4.1.1466.0=#04024869'
147
147
*
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
+ *
148
159
* @returns {string }
149
160
*/
150
- toString ( ) {
161
+ toString ( { unescaped = false } = { } ) {
151
162
let result = ''
152
163
const isHexEncodedValue = val => / ^ # ( [ 0 - 9 a - f A - F ] { 2 } ) + $ / . test ( val ) === true
153
164
@@ -163,7 +174,7 @@ class RDN {
163
174
}
164
175
result += encoded
165
176
} else {
166
- result += escapeValue ( entry . value )
177
+ result += unescaped === false ? escapeValue ( entry . value ) : entry . value
167
178
}
168
179
169
180
result += '+'
Original file line number Diff line number Diff line change @@ -132,6 +132,13 @@ tap.test('toString', t => {
132
132
t . equal ( rdn . toString ( ) , 'cn=#0403666f6f' )
133
133
} )
134
134
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
+
135
142
t . end ( )
136
143
} )
137
144
You can’t perform that action at this time.
0 commit comments