From ab196040b426c4273cc0e4f75e805f42c8a59b12 Mon Sep 17 00:00:00 2001 From: Jamstah Date: Tue, 11 Jan 2011 14:23:15 +0000 Subject: [PATCH 1/2] Add breaking tests. --- spec/unit/ldap/filter_spec.rb | 6 +++--- test/test_filter.rb | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/spec/unit/ldap/filter_spec.rb b/spec/unit/ldap/filter_spec.rb index 623f032..9c08436 100644 --- a/spec/unit/ldap/filter_spec.rb +++ b/spec/unit/ldap/filter_spec.rb @@ -76,8 +76,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 \ No newline at end of file +end diff --git a/test/test_filter.rb b/test/test_filter.rb index 88495f1..faa42c4 100644 --- a/test/test_filter.rb +++ b/test/test_filter.rb @@ -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) From 0b0688d434316c1ae84f45150574068338f60df6 Mon Sep 17 00:00:00 2001 From: Jamstah Date: Tue, 11 Jan 2011 14:23:40 +0000 Subject: [PATCH 2/2] Add correct filter characters. --- lib/net/ldap/filter.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/net/ldap/filter.rb b/lib/net/ldap/filter.rb index 4e8aec8..9a7192b 100644 --- a/lib/net/ldap/filter.rb +++ b/lib/net/ldap/filter.rb @@ -249,12 +249,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(