Merge branch 'filter_escaping' of https://github.com/Jamstah/ruby-net-ldap into Jamstah-filter_escaping

This commit is contained in:
Austin Ziegler 2011-03-17 22:37:44 -04:00
commit 2a63ae72b9
3 changed files with 14 additions and 8 deletions

View file

@ -229,12 +229,11 @@ class Net::LDAP::Filter
# string using a single backslash ('\') as escape.
#
ESCAPES = {
'!' => '21', # EXCLAMATION = %x21 ; exclamation mark ("!")
'&' => '26', # AMPERSAND = %x26 ; ampersand (or AND symbol) ("&")
'*' => '2A', # ASTERISK = %x2A ; asterisk ("*")
':' => '3A', # COLON = %x3A ; colon (":")
'|' => '7C', # VERTBAR = %x7C ; vertical bar (or pipe) ("|")
'~' => '7E', # TILDE = %x7E ; tilde ("~")
"\0" => '00', # NUL = %x00 ; null character
'*' => '2A', # ASTERISK = %x2A ; asterisk ("*")
'(' => '28', # LPARENS = %x28 ; left parenthesis ("(")
')' => '29', # RPARENS = %x29 ; right parenthesis (")")
'\\' => '5C', # ESC = %x5C ; esc (or backslash) ("\")
}
# Compiled character class regexp using the keys from the above hash.
ESCAPE_RE = Regexp.new(

View file

@ -77,8 +77,8 @@ describe Net::LDAP::Filter do
end
end
describe "<- .escape(str)" do
it "should escape !, &, *, :, | and ~" do
Net::LDAP::Filter.escape('!&*:|~').should == "\\21\\26\\2A\\3A\\7C\\7E"
it "should escape nul, *, (, ) and \\" do
Net::LDAP::Filter.escape("\0*()\\").should == "\\00\\2A\\28\\29\\5C"
end
end
end

View file

@ -24,6 +24,13 @@ class TestFilter < Test::Unit::TestCase
assert_equal("(uid=george *)", Filter.eq("uid", "george *").to_s)
end
def test_convenience_filters
assert_equal("(uid=\\2A)", Filter.equals("uid", "*").to_s)
assert_equal("(uid=\\28*)", Filter.begins("uid", "(").to_s)
assert_equal("(uid=*\\29)", Filter.ends("uid", ")").to_s)
assert_equal("(uid=*\\5C*)", Filter.contains("uid", "\\").to_s)
end
def test_c2
assert_equal("(uid=george *)",
Filter.from_rfc2254("uid=george *").to_rfc2254)