From 61890b51e874eccc9e6d4e271cbaa6befed5809c Mon Sep 17 00:00:00 2001 From: Anuj Patel Date: Sat, 25 Mar 2017 13:35:40 -0700 Subject: [PATCH] Update filter.rb Fixed Exception: incompatible character encodings: ASCII-8BIT and UTF-8 The binary form of 5936AE79-664F-44EA-BCCB-5C39399514C6 triggers a BINARY -> UTF-8 conversion error --- lib/net/ldap/filter.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/net/ldap/filter.rb b/lib/net/ldap/filter.rb index 7f418ae3..6f064488 100644 --- a/lib/net/ldap/filter.rb +++ b/lib/net/ldap/filter.rb @@ -645,8 +645,15 @@ def match(entry) ## # Converts escaped characters (e.g., "\\28") to unescaped characters + # @note slawson20170317: Don't attempt to unescape 16 byte binary data which we assume are objectGUIDs + # The binary form of 5936AE79-664F-44EA-BCCB-5C39399514C6 triggers a BINARY -> UTF-8 conversion error def unescape(right) - right.to_s.gsub(/\\([a-fA-F\d]{2})/) { [$1.hex].pack("U") } + right = right.to_s + if right.length == 16 && right.encoding == Encoding::BINARY + right + else + right.to_s.gsub(/\\([a-fA-F\d]{2})/) { [$1.hex].pack("U") } + end end private :unescape