commit f402f3a12882064c8316f32d281598f8fc048000
parent 916222b84651bc1b63f77cfb8e5a109f026dd074
Author: Dan Callaghan <djc@djc.id.au>
Date: Mon, 18 Apr 2022 21:37:43 +1000
inject extra padding when decoding RFC2047 words
The = padding characters are optional in base64-encoded RFC2047 words,
but on Ruby 2.0 if the final padding is missing .unpack('m*') will
silently discard the last byte, producing an invalid word.
This fixes the RFC2047 test cases on Ruby 2.0.
Diffstat:
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/lib/sup/rfc2047.rb b/lib/sup/rfc2047.rb
@@ -37,9 +37,10 @@ module Rfc2047
# B64 or QP decode, as necessary:
case encoding
when 'b', 'B'
- #puts text
- text = text.unpack('m*')[0]
- #puts text.dump
+ ## Padding is optional in RFC 2047 words. Add some extra padding
+ ## before decoding the base64, otherwise on Ruby 2.0 the final byte
+ ## might be discarded.
+ text = (text + '===').unpack('m*')[0]
when 'q', 'Q'
# RFC 2047 has a variant of quoted printable where a ' ' character