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)
291
291
case b . ber_identifier
292
292
when 0x80 # context-specific primitive 0, SubstringFilter "initial"
293
293
raise Net ::LDAP ::LdapError , "Unrecognized substring filter; bad initial value." if str . length > 0
294
- str += b
294
+ str += escape ( b )
295
295
when 0x81 # context-specific primitive 0, SubstringFilter "any"
296
- str += "*#{ b } "
296
+ str += "*#{ escape ( b ) } "
297
297
when 0x82 # context-specific primitive 0, SubstringFilter "final"
298
- str += "*#{ b } "
298
+ str += "*#{ escape ( b ) } "
299
299
final = true
300
300
end
301
301
}
@@ -509,17 +509,17 @@ def to_ber
509
509
first = nil
510
510
ary . shift
511
511
else
512
- first = ary . shift . to_ber_contextspecific ( 0 )
512
+ first = unescape ( ary . shift ) . to_ber_contextspecific ( 0 )
513
513
end
514
514
515
515
if ary . last . empty?
516
516
last = nil
517
517
ary . pop
518
518
else
519
- last = ary . pop . to_ber_contextspecific ( 2 )
519
+ last = unescape ( ary . pop ) . to_ber_contextspecific ( 2 )
520
520
end
521
521
522
- seq = ary . map { |e | e . to_ber_contextspecific ( 1 ) }
522
+ seq = ary . map { |e | unescape ( e ) . to_ber_contextspecific ( 1 ) }
523
523
seq . unshift first if first
524
524
seq . push last if last
525
525
Original file line number Diff line number Diff line change @@ -81,4 +81,35 @@ def eq(attribute, value)
81
81
Net ::LDAP ::Filter . escape ( "\0 *()\\ " ) . should == "\\ 00\\ 2A\\ 28\\ 29\\ 5C"
82
82
end
83
83
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
84
115
end
You can’t perform that action at this time.
0 commit comments