From 3a101bed4fd21a9c572c94de2d3efbde8385934d Mon Sep 17 00:00:00 2001 From: Brian Weaver Date: Tue, 25 Aug 2015 14:20:09 -0400 Subject: [PATCH 1/2] Server strings are always UTF-8 --- lib/net/ber.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/net/ber.rb b/lib/net/ber.rb index b8992a92..f7f1bdde 100644 --- a/lib/net/ber.rb +++ b/lib/net/ber.rb @@ -296,9 +296,8 @@ def to_arr class Net::BER::BerIdentifiedString < String attr_accessor :ber_identifier def initialize args + args.force_encoding('UTF-8') if args.respond_to(:force_encoding) super args - # LDAP uses UTF-8 encoded strings - self.encode('UTF-8') if self.respond_to?(:encoding) rescue self end end From 5817269273e0d658d5fe56bd2bbf229c4a8c9638 Mon Sep 17 00:00:00 2001 From: Brian Weaver Date: Tue, 25 Aug 2015 14:49:43 -0400 Subject: [PATCH 2/2] Correctly encode to UTF-8 when possible --- lib/net/ber.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/net/ber.rb b/lib/net/ber.rb index f7f1bdde..b4b9e9da 100644 --- a/lib/net/ber.rb +++ b/lib/net/ber.rb @@ -296,8 +296,11 @@ def to_arr class Net::BER::BerIdentifiedString < String attr_accessor :ber_identifier def initialize args - args.force_encoding('UTF-8') if args.respond_to(:force_encoding) - super args + super begin + args.respond_to?(:encode) ? args.encode('UTF-8') : args + rescue + args + end end end