Navigation Menu

Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Remove 'binary' encoding assert - add tests
Browse files Browse the repository at this point in the history
Don't write large characters to buffers with binary encoding. You will be
silently injured.
  • Loading branch information
ry committed May 16, 2011
1 parent 249361c commit 103a450
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/node.cc
Expand Up @@ -1203,7 +1203,6 @@ ssize_t DecodeWrite(char *buf,

for (size_t i = 0; i < buflen; i++) {
unsigned char *b = reinterpret_cast<unsigned char*>(&twobytebuf[i]);
assert(b[1] == 0);
buf[i] = b[0];
}

Expand Down
15 changes: 15 additions & 0 deletions test/simple/test-buffer.js
Expand Up @@ -505,3 +505,18 @@ assert.equal(0x6f, z[1]);
var b = new SlowBuffer(10);
b.write('あいうえお', 'ucs2');
assert.equal(b.toString('ucs2'), 'あいうえお');

// Binary encoding should write only one byte per character.
var b = Buffer([0xde, 0xad, 0xbe, 0xef]);
var s = String.fromCharCode(0xffff);
b.write(s, 0, 'binary')
assert.equal(0xff, b[0]);
assert.equal(0xad, b[1]);
assert.equal(0xbe, b[2]);
assert.equal(0xef, b[3]);
s = String.fromCharCode(0xaaee);
b.write(s, 0, 'binary')
assert.equal(0xee, b[0]);
assert.equal(0xad, b[1]);
assert.equal(0xbe, b[2]);
assert.equal(0xef, b[3]);

0 comments on commit 103a450

Please sign in to comment.