Skip to content

Commit 2a63ae7

Browse files
author
Austin Ziegler
committed
Merge branch 'filter_escaping' of https://github.com/Jamstah/ruby-net-ldap into Jamstah-filter_escaping
2 parents 50c76e1 + 0b0688d commit 2a63ae7

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

lib/net/ldap/filter.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,11 @@ def present?(attribute)
229229
# string using a single backslash ('\') as escape.
230230
#
231231
ESCAPES = {
232-
'!' => '21', # EXCLAMATION = %x21 ; exclamation mark ("!")
233-
'&' => '26', # AMPERSAND = %x26 ; ampersand (or AND symbol) ("&")
234-
'*' => '2A', # ASTERISK = %x2A ; asterisk ("*")
235-
':' => '3A', # COLON = %x3A ; colon (":")
236-
'|' => '7C', # VERTBAR = %x7C ; vertical bar (or pipe) ("|")
237-
'~' => '7E', # TILDE = %x7E ; tilde ("~")
232+
"\0" => '00', # NUL = %x00 ; null character
233+
'*' => '2A', # ASTERISK = %x2A ; asterisk ("*")
234+
'(' => '28', # LPARENS = %x28 ; left parenthesis ("(")
235+
')' => '29', # RPARENS = %x29 ; right parenthesis (")")
236+
'\\' => '5C', # ESC = %x5C ; esc (or backslash) ("\")
238237
}
239238
# Compiled character class regexp using the keys from the above hash.
240239
ESCAPE_RE = Regexp.new(

spec/unit/ldap/filter_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ def eq(attribute, value)
7777
end
7878
end
7979
describe "<- .escape(str)" do
80-
it "should escape !, &, *, :, | and ~" do
81-
Net::LDAP::Filter.escape('!&*:|~').should == "\\21\\26\\2A\\3A\\7C\\7E"
80+
it "should escape nul, *, (, ) and \\" do
81+
Net::LDAP::Filter.escape("\0*()\\").should == "\\00\\2A\\28\\29\\5C"
8282
end
8383
end
8484
end

test/test_filter.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ def test_to_s
2424
assert_equal("(uid=george *)", Filter.eq("uid", "george *").to_s)
2525
end
2626

27+
def test_convenience_filters
28+
assert_equal("(uid=\\2A)", Filter.equals("uid", "*").to_s)
29+
assert_equal("(uid=\\28*)", Filter.begins("uid", "(").to_s)
30+
assert_equal("(uid=*\\29)", Filter.ends("uid", ")").to_s)
31+
assert_equal("(uid=*\\5C*)", Filter.contains("uid", "\\").to_s)
32+
end
33+
2734
def test_c2
2835
assert_equal("(uid=george *)",
2936
Filter.from_rfc2254("uid=george *").to_rfc2254)

0 commit comments

Comments
 (0)