Skip to content

Commit

Permalink
Fix toString('base64') bug
Browse files Browse the repository at this point in the history
Thanks to Stepan Stolyarov for the test case.
  • Loading branch information
ry committed Aug 4, 2010
1 parent 24c6d26 commit 7db5c8a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions test/simple/test-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.