Skip to content

Commit

Permalink
[Net] Fix MimeBase64 so long encoded outputs are broken after 76 colu…
Browse files Browse the repository at this point in the history
…mns. The decoder still works with this change. Add a test to prove the new behavior
  • Loading branch information
Whiteknight committed Sep 9, 2012
1 parent 697efd9 commit 3d7999a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/net/MimeBase64.winxed
Expand Up @@ -6,10 +6,6 @@
*/ */
class Rosella.Net.MimeBase64 class Rosella.Net.MimeBase64
{ {
// TODO: MIME standard says lines need to be broken after 76 characters. Implement
// this for encode and decode. See https://github.com/parrot/parrot/issues/826
// for more details.

const string PRINTABLE_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; const string PRINTABLE_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var eight_to_six; var eight_to_six;
var six_to_eight; var six_to_eight;
Expand Down Expand Up @@ -56,6 +52,7 @@ class Rosella.Net.MimeBase64
{ {
var s = self.six_to_eight; var s = self.six_to_eight;
int len = elements(buf); int len = elements(buf);
int num_frames = 0;


var result = new 'ByteBuffer'; var result = new 'ByteBuffer';
for (int i = 0; i < len; ) { for (int i = 0; i < len; ) {
Expand All @@ -72,6 +69,9 @@ class Rosella.Net.MimeBase64
push(result, int(s[six_1])); push(result, int(s[six_1]));
push(result, int(s[six_2])); push(result, int(s[six_2]));
push(result, int(s[six_3])); push(result, int(s[six_3]));
num_frames++;
if (num_frames % 19 == 0)
push(result, ASCII_LINE_FEED);
} }


int len_mod_3 = len % 3; int len_mod_3 = len % 3;
Expand Down
11 changes: 11 additions & 0 deletions t/net/MimeBase64.t
Expand Up @@ -33,6 +33,17 @@ class Test_Rosella_Net_MimeBase64
string e = Rosella.Net.default_mime_encoder().encode(s); string e = Rosella.Net.default_mime_encoder().encode(s);
self.assert.str_equal(e, "wqI="); self.assert.str_equal(e, "wqI=");
} }

function long_lines()
{
self.status.verify("Test that encoded output breaks lines after 76 chars");
var obj = create_new();

string arg_0 = "this is a test of a much longer line that should be broken after about 76 bytes or so";
string result = obj.encode(arg_0);
string expected = "dGhpcyBpcyBhIHRlc3Qgb2YgYSBtdWNoIGxvbmdlciBsaW5lIHRoYXQgc2hvdWxkIGJlIGJyb2tl\x{A}biBhZnRlciBhYm91dCA3NiBieXRlcyBvciBzbw==";
self.assert.str_equal(result, expected);
}
} }


function initialize_test[anon](var context) function initialize_test[anon](var context)
Expand Down

0 comments on commit 3d7999a

Please sign in to comment.