Skip to content

Commit 656039c

Browse files
committed
Gracefully fall back if string cannot be encoded.
1 parent 51597ea commit 656039c

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
@@ -20,7 +20,11 @@ def raw_utf8_encoded
2020
if self.respond_to?(:encode)
2121
# Strings should be UTF-8 encoded according to LDAP.
2222
# However, the BER code is not necessarily valid UTF-8
23-
self.encode('UTF-8').force_encoding('ASCII-8BIT')
23+
begin
24+
self.encode('UTF-8').force_encoding('ASCII-8BIT')
25+
rescue Encoding::UndefinedConversionError
26+
self
27+
end
2428
else
2529
self
2630
end

0 commit comments

Comments
 (0)