Browse Source

Remove 'binary' encoding assert - add tests

Don't write large characters to buffers with binary encoding. You will be
silently injured.
v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
103a450d3a
  1. 1
      src/node.cc
  2. 15
      test/simple/test-buffer.js

1
src/node.cc

@ -1203,7 +1203,6 @@ ssize_t DecodeWrite(char *buf,
for (size_t i = 0; i < buflen; i++) { for (size_t i = 0; i < buflen; i++) {
unsigned char *b = reinterpret_cast<unsigned char*>(&twobytebuf[i]); unsigned char *b = reinterpret_cast<unsigned char*>(&twobytebuf[i]);
assert(b[1] == 0);
buf[i] = b[0]; buf[i] = b[0];
} }

15
test/simple/test-buffer.js

@ -505,3 +505,18 @@ assert.equal(0x6f, z[1]);
var b = new SlowBuffer(10); var b = new SlowBuffer(10);
b.write('あいうえお', 'ucs2'); b.write('あいうえお', 'ucs2');
assert.equal(b.toString('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]);

Loading…
Cancel
Save