From d2862209889e6711444259a55e869d7dcb0580c3 Mon Sep 17 00:00:00 2001 From: Andre Marques Lee Date: Wed, 3 Dec 2014 00:21:28 +0000 Subject: [PATCH] Implemented a couple of bug fixes: * Connection#search now does more graceful nil-checking in its ensure clause, reducing cryptic crash messages * Filter class methods should now be able to gracefully accept numeric literals as filter rhs values --- lib/net/ldap/connection.rb | 3 ++- lib/net/ldap/filter.rb | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/net/ldap/connection.rb b/lib/net/ldap/connection.rb index 91fb7e90..c690a8c3 100644 --- a/lib/net/ldap/connection.rb +++ b/lib/net/ldap/connection.rb @@ -562,12 +562,13 @@ def search(args = nil) result_pdu || OpenStruct.new(:status => :failure, :result_code => Net::LDAP::ResultCodeOperationsError, :message => "Invalid search") end # instrument ensure + # clean up message queue for this search messages = message_queue.delete(message_id) # in the exceptional case some messages were *not* consumed from the queue, # instrument the event but do not fail. - unless messages.empty? + unless messages.nil? or messages.empty? instrument "search_messages_unread.net_ldap_connection", message_id: message_id, messages: messages end diff --git a/lib/net/ldap/filter.rb b/lib/net/ldap/filter.rb index 5d91f9f6..5a2528bd 100644 --- a/lib/net/ldap/filter.rb +++ b/lib/net/ldap/filter.rb @@ -644,10 +644,18 @@ def match(entry) end ## - # Converts escaped characters (e.g., "\\28") to unescaped characters + # If the argument is a string, converts escaped characters (e.g., "\\28") to unescaped characters. + # If the argument is a number, just return as-is. + # Otherwise, an exception is thrown and the rhs argument is rejected. # ("("). def unescape(right) - right.gsub(/\\([a-fA-F\d]{2})/) { [$1.hex].pack("U") } + if defined? right.gsub + right.gsub(/\\([a-fA-F\d]{2})/) { [$1.hex].pack("U") } + elsif right.is_a? Fixnum + right.to_s + else + raise ArgumentError, "Did not know how to convert argument \"#{right}\" into the rhs of an LDAP filter" + end end private :unescape