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