Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[Net] Fix MimeBase64 so long encoded outputs are broken after 76 colu…

…mns. The decoder still works with this change. Add a test to prove the new behavior
  • Loading branch information...
commit 3d7999ae0bd64a6fe0616aa707f69f21b708fa97 1 parent 697efd9
@Whiteknight authored
Showing with 15 additions and 4 deletions.
  1. +4 −4 src/net/MimeBase64.winxed
  2. +11 −0 t/net/MimeBase64.t
View
8 src/net/MimeBase64.winxed
@@ -6,10 +6,6 @@
*/
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+/";
var eight_to_six;
var six_to_eight;
@@ -56,6 +52,7 @@ class Rosella.Net.MimeBase64
{
var s = self.six_to_eight;
int len = elements(buf);
+ int num_frames = 0;
var result = new 'ByteBuffer';
for (int i = 0; i < len; ) {
@@ -72,6 +69,9 @@ class Rosella.Net.MimeBase64
push(result, int(s[six_1]));
push(result, int(s[six_2]));
push(result, int(s[six_3]));
+ num_frames++;
+ if (num_frames % 19 == 0)
+ push(result, ASCII_LINE_FEED);
}
int len_mod_3 = len % 3;
View
11 t/net/MimeBase64.t
@@ -33,6 +33,17 @@ class Test_Rosella_Net_MimeBase64
string e = Rosella.Net.default_mime_encoder().encode(s);
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)
Please sign in to comment.
Something went wrong with that request. Please try again.