Remove 'binary' encoding assert - add tests
Don't write large characters to buffers with binary encoding. You will be silently injured.
This commit is contained in:
parent
249361cab7
commit
103a450d3a
@ -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];
|
||||
}
|
||||
|
||||
|
@ -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]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user