Permalink
Browse files

Fix toString('base64') bug

Thanks to Stepan Stolyarov for the test case.
  • Loading branch information...
1 parent 24c6d26 commit 7db5c8a10da7d864dc82a10867044346d11d9666 @ry ry committed Aug 4, 2010
Showing with 9 additions and 1 deletion.
  1. +1 −1 src/node_buffer.cc
  2. +8 −0 test/simple/test-buffer.js
View
2 src/node_buffer.cc
@@ -327,7 +327,7 @@ Handle<Value> Buffer::Base64Slice(const Arguments &args) {
int out_len = (n + 2 - ((n + 2) % 3)) / 3 * 4;
char *out = new char[out_len];
- char bitbuf[3];
+ uint8_t bitbuf[3];
int i = start; // data() index
int j = 0; // out index
char c;
View
8 test/simple/test-buffer.js
@@ -306,3 +306,11 @@ assert.equal(new Buffer('72INjkR5fchcxk9+VgdGPFJDxUBFR5/rMFsghgxADiw', 'base64
assert.equal(new Buffer('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg==', 'base64').length, 31);
assert.equal(new Buffer('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg=', 'base64').length, 31);
assert.equal(new Buffer('w69jACy6BgZmaFvv96HG6MYksWytuZu3T1FvGnulPg', 'base64').length, 31);
+
+// This string encodes single '.' character in UTF-16
+dot = new Buffer('//4uAA==', 'base64');
+assert.equal(dot[0], 0xff);
+assert.equal(dot[1], 0xfe);
+assert.equal(dot[2], 0x2e);
+assert.equal(dot[3], 0x00);
+assert.equal(dot.toString('base64'), '//4uAA==');

0 comments on commit 7db5c8a

Please sign in to comment.