bug with unpack('m') / pack('m') ?

T

tribalvibes

Having a strange ruby encoding encounter:

ruby-1.9.2-p180 :618 > s = "a8dnsjg8aiw8jq".ljust(16,'=')
=> "a8dnsjg8aiw8jq=="
ruby-1.9.2-p180 :619 > s.size
=> 16

ruby-1.9.2-p180 :620 > s.unpack('m0')
ArgumentError: invalid base64
from (irb):631:in `unpack'

ruby-1.9.2-p180 :621 > s.unpack('m')
=> ["k\xC7g\xB28<j,<\x8E"]
ruby-1.9.2-p180 :622 > s.unpack('m').first.size
=> 10

ruby-1.9.2-p180 :623 > s.unpack('m').pack('m')
=> "a8dnsjg8aiw8jg==\n"
ruby-1.9.2-p180 :624 > s.unpack('m').pack('m') == s
=> false

Any idea why this is not symmetric!? And why is 'm0' (decode64_strict)
not working at all? The input string is padded out to a multiple of 4
characters in the base64 alphabet. Here it's 14 x 6 bits = 84 bits
which is 10 1/2 8-bit bytes, i.e. 11 bytes. But the decoded string
seems to drop the last nybble?

Am I missing something obvious or is this a bug? Workaround? cf.
http://www.ietf.org/rfc/rfc4648.txt

http://stackoverflow.com/questions/7063737/ruby-base64-encode-decode-unpackm-troubles
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top