File tree 2 files changed +12
-12
lines changed
2 files changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -192,27 +192,19 @@ def to_s
192
192
# http://tools.ietf.org/html/rfc2253 section 2.4 lists these exceptions
193
193
# for dn values. All of the following must be escaped in any normal string
194
194
# using a single backslash ('\') as escape.
195
- ESCAPES = {
196
- ',' => ',' ,
197
- '+' => '+' ,
198
- '"' => '"' ,
199
- '\\' => '\\' ,
200
- '<' => '<' ,
201
- '>' => '>' ,
202
- ';' => ';' ,
203
- }
195
+ ESCAPES = %w[ , + " \\ < > ; ]
204
196
205
- # Compiled character class regexp using the keys from the above hash , and
197
+ # Compiled character class regexp using the values from the above list , and
206
198
# checking for a space or # at the start, or space at the end, of the
207
199
# string.
208
200
ESCAPE_RE = Regexp . new ( "(^ |^#| $|[" +
209
- ESCAPES . keys . map { |e | Regexp . escape ( e ) } . join +
201
+ ESCAPES . map { |e | Regexp . escape ( e ) } . join +
210
202
"])" )
211
203
212
204
##
213
205
# Escape a string for use in a DN value
214
206
def self . escape ( string )
215
- string . gsub ( ESCAPE_RE ) { |char | "\\ " + ESCAPES [ char ] }
207
+ string . gsub ( ESCAPE_RE ) { |char | "\\ " + char }
216
208
end
217
209
218
210
##
Original file line number Diff line number Diff line change @@ -6,6 +6,14 @@ def test_escape
6
6
assert_equal '\\,\\+\\"\\\\\\<\\>\\;' , Net ::LDAP ::DN . escape ( ',+"\\<>;' )
7
7
end
8
8
9
+ def test_escape_pound_sign
10
+ assert_equal '\\#test' , Net ::LDAP ::DN . escape ( '#test' )
11
+ end
12
+
13
+ def test_escape_space
14
+ assert_equal '\\ before_after\\ ' , Net ::LDAP ::DN . escape ( ' before_after ' )
15
+ end
16
+
9
17
def test_escape_on_initialize
10
18
dn = Net ::LDAP ::DN . new ( 'cn' , ',+"\\<>;' , 'ou=company' )
11
19
assert_equal 'cn=\\,\\+\\"\\\\\\<\\>\\;,ou=company' , dn . to_s
You can’t perform that action at this time.
0 commit comments