Browse files

Gracefully fall back if string cannot be encoded.

  • Loading branch information...
1 parent 51597ea commit 656039cee0708bb7cb5673eade7a821df03b5d9a @justcfx2u justcfx2u committed May 1, 2012
Showing with 5 additions and 1 deletion.
  1. +5 −1 lib/net/ber/core_ext/string.rb
View
6 lib/net/ber/core_ext/string.rb
@@ -20,7 +20,11 @@ def raw_utf8_encoded
if self.respond_to?(:encode)
# Strings should be UTF-8 encoded according to LDAP.
# However, the BER code is not necessarily valid UTF-8
- self.encode('UTF-8').force_encoding('ASCII-8BIT')
+ begin
+ self.encode('UTF-8').force_encoding('ASCII-8BIT')
+ rescue Encoding::UndefinedConversionError
+ self
+ end
else
self
end

1 comment on commit 656039c

@twiz718

When will the be released to Rubygems? Thanks

Please sign in to comment.