File tree Expand file tree Collapse file tree 2 files changed +12
-12
lines changed Expand file tree Collapse file tree 2 files changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -192,27 +192,19 @@ def to_s
192192 # http://tools.ietf.org/html/rfc2253 section 2.4 lists these exceptions
193193 # for dn values. All of the following must be escaped in any normal string
194194 # using a single backslash ('\') as escape.
195- ESCAPES = {
196- ',' => ',' ,
197- '+' => '+' ,
198- '"' => '"' ,
199- '\\' => '\\' ,
200- '<' => '<' ,
201- '>' => '>' ,
202- ';' => ';' ,
203- }
195+ ESCAPES = %w[ , + " \\ < > ; ]
204196
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
206198 # checking for a space or # at the start, or space at the end, of the
207199 # string.
208200 ESCAPE_RE = Regexp . new ( "(^ |^#| $|[" +
209- ESCAPES . keys . map { |e | Regexp . escape ( e ) } . join +
201+ ESCAPES . map { |e | Regexp . escape ( e ) } . join +
210202 "])" )
211203
212204 ##
213205 # Escape a string for use in a DN value
214206 def self . escape ( string )
215- string . gsub ( ESCAPE_RE ) { |char | "\\ " + ESCAPES [ char ] }
207+ string . gsub ( ESCAPE_RE ) { |char | "\\ " + char }
216208 end
217209
218210 ##
Original file line number Diff line number Diff line change @@ -6,6 +6,14 @@ def test_escape
66 assert_equal '\\,\\+\\"\\\\\\<\\>\\;' , Net ::LDAP ::DN . escape ( ',+"\\<>;' )
77 end
88
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+
917 def test_escape_on_initialize
1018 dn = Net ::LDAP ::DN . new ( 'cn' , ',+"\\<>;' , 'ou=company' )
1119 assert_equal 'cn=\\,\\+\\"\\\\\\<\\>\\;,ou=company' , dn . to_s
You can’t perform that action at this time.
0 commit comments