Gracefully fall back if string cannot be encoded.

This commit is contained in:
Harold A. Jones II 2012-04-30 22:03:55 -04:00
parent 51597eae9a
commit 656039cee0

View file

@ -20,7 +20,11 @@ module Net::BER::Extensions::String
if self.respond_to?(:encode) if self.respond_to?(:encode)
# Strings should be UTF-8 encoded according to LDAP. # Strings should be UTF-8 encoded according to LDAP.
# However, the BER code is not necessarily valid UTF-8 # However, the BER code is not necessarily valid UTF-8
begin
self.encode('UTF-8').force_encoding('ASCII-8BIT') self.encode('UTF-8').force_encoding('ASCII-8BIT')
rescue Encoding::UndefinedConversionError
self
end
else else
self self
end end