Skip to content

Commit 3f819de

Browse files
author
Rory O'Connell
committed
Merge pull request ruby-ldap#41 from justcfx2u/master
Fall back if string cannot be encoded
2 parents b859051 + becfa8e commit 3f819de

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/net/ber/core_ext/string.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ def raw_utf8_encoded
2828
if self.respond_to?(:encode)
2929
# Strings should be UTF-8 encoded according to LDAP.
3030
# However, the BER code is not necessarily valid UTF-8
31-
self.encode('UTF-8').force_encoding('ASCII-8BIT')
31+
begin
32+
self.encode('UTF-8').force_encoding('ASCII-8BIT')
33+
rescue Encoding::UndefinedConversionError
34+
self
35+
end
3236
else
3337
self
3438
end

0 commit comments

Comments
 (0)