Skip to content

Commit ca5d415

Browse files
committed
Don't change the encoding of binary data to UTF-8.
It does not make sense to change the encoding of binary data, i.e., data that already has the encoding of ASCII-8BIT or BINARY. Data stored in the jpegPhoto attribute is an example. irb(main):001:0> binstring = ['FFD8FFE000104A46494600'].pack('H*') => "\xFF\xD8\xFF\xE0\x00\x10JFIF\x00" irb(main):002:0> binstring.encoding => #<Encoding:ASCII-8BIT> irb(main):003:0> binstring.respond_to?(:encode) => true irb(main):004:0> binstring.encode('UTF-8') Encoding::UndefinedConversionError: "\xFF" from ASCII-8BIT to UTF-8 from (irb):4:in `encode' from (irb):4 from /usr/bin/irb:12:in `<main>' irb(main):005:0>
1 parent bbef82f commit ca5d415

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/net/ber/core_ext/string.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def to_ber_bin(code = 0x04)
2525
end
2626

2727
def raw_utf8_encoded
28-
if self.respond_to?(:encode)
28+
if self.respond_to?(:encode) && self.encoding.to_s != 'ASCII-8BIT'
2929
# Strings should be UTF-8 encoded according to LDAP.
3030
# However, the BER code is not necessarily valid UTF-8
3131
begin

0 commit comments

Comments
 (0)