Don't change the encoding of binary data to UTF-8. #71

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants

wandns commented Jul 30, 2013

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

'
irb(main):005:0>

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>
Member

jch commented Oct 7, 2014

@wandns sorry for the slow response, but we're rebooting development efforts with https://groups.google.com/d/msg/ruby-ldap/3y6g1Oqgvd0/vy5DaAcwF_cJ. Can you rebase your changes off the latest master, and add some tests?

@jch jch closed this Oct 31, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment