File tree Expand file tree Collapse file tree 2 files changed +37
-6
lines changed Expand file tree Collapse file tree 2 files changed +37
-6
lines changed Original file line number Diff line number Diff line change @@ -291,11 +291,11 @@ def parse_ber(ber)
291291 case b . ber_identifier
292292 when 0x80 # context-specific primitive 0, SubstringFilter "initial"
293293 raise Net ::LDAP ::LdapError , "Unrecognized substring filter; bad initial value." if str . length > 0
294- str += b
294+ str += escape ( b )
295295 when 0x81 # context-specific primitive 0, SubstringFilter "any"
296- str += "*#{ b } "
296+ str += "*#{ escape ( b ) } "
297297 when 0x82 # context-specific primitive 0, SubstringFilter "final"
298- str += "*#{ b } "
298+ str += "*#{ escape ( b ) } "
299299 final = true
300300 end
301301 }
@@ -509,17 +509,17 @@ def to_ber
509509 first = nil
510510 ary . shift
511511 else
512- first = ary . shift . to_ber_contextspecific ( 0 )
512+ first = unescape ( ary . shift ) . to_ber_contextspecific ( 0 )
513513 end
514514
515515 if ary . last . empty?
516516 last = nil
517517 ary . pop
518518 else
519- last = ary . pop . to_ber_contextspecific ( 2 )
519+ last = unescape ( ary . pop ) . to_ber_contextspecific ( 2 )
520520 end
521521
522- seq = ary . map { |e | e . to_ber_contextspecific ( 1 ) }
522+ seq = ary . map { |e | unescape ( e ) . to_ber_contextspecific ( 1 ) }
523523 seq . unshift first if first
524524 seq . push last if last
525525
Original file line number Diff line number Diff line change @@ -81,4 +81,35 @@ def eq(attribute, value)
8181 Net ::LDAP ::Filter . escape ( "\0 *()\\ " ) . should == "\\ 00\\ 2A\\ 28\\ 29\\ 5C"
8282 end
8383 end
84+
85+ context 'with a well-known BER string' do
86+ ber = "\xa4 \x2d " \
87+ "\x04 \x0b " "objectclass" \
88+ "\x30 \x1e " \
89+ "\x80 \x08 " "foo" "*\\ " "bar" \
90+ "\x81 \x08 " "foo" "*\\ " "bar" \
91+ "\x82 \x08 " "foo" "*\\ " "bar"
92+
93+ describe "<- .to_ber" do
94+ [
95+ "foo" "\\ 2A\\ 5C" "bar" ,
96+ "foo" "\\ 2a\\ 5c" "bar" ,
97+ "foo" "\\ 2A\\ 5c" "bar" ,
98+ "foo" "\\ 2a\\ 5C" "bar"
99+ ] . each do |escaped |
100+ it 'unescapes escaped characters' do
101+ filter = Net ::LDAP ::Filter . eq ( "objectclass" , "#{ escaped } *#{ escaped } *#{ escaped } " )
102+ filter . to_ber . should == ber
103+ end
104+ end
105+ end
106+
107+ describe '<- .parse_ber' do
108+ it 'escapes characters' do
109+ escaped = Net ::LDAP ::Filter . escape ( "foo" "*\\ " "bar" )
110+ filter = Net ::LDAP ::Filter . parse_ber ( ber . read_ber ( Net ::LDAP ::AsnSyntax ) )
111+ filter . to_s . should == "(objectclass=#{ escaped } *#{ escaped } *#{ escaped } )"
112+ end
113+ end
114+ end
84115end
You can’t perform that action at this time.
0 commit comments