Skip to content

Commit 2b69933

Browse files
committed
test: add test for unaligned ucs2 buffer write
Between nodejs#3410 and nodejs#7645, bytes were swapped twice on bigendian platforms if buffer was not two-byte aligned. See comment in nodejs#7645.
1 parent 62ba6c8 commit 2b69933

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

test/parallel/test-buffer-alloc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,12 @@ assert.strictEqual('<Buffer 81 a3 66 6f 6f a3 62 61 72>', x.inspect());
585585
assert.strictEqual(b.toString(encoding), 'あいうえお');
586586
});
587587

588+
['ucs2', 'ucs-2', 'utf16le', 'utf-16le'].forEach((encoding) => {
589+
const b = Buffer.allocUnsafe(11);
590+
b.write('あいうえお', 1, encoding);
591+
assert.strictEqual(b.toString(encoding, 1), 'あいうえお');
592+
});
593+
588594
{
589595
// latin1 encoding should write only one byte per character.
590596
const b = Buffer.from([0xde, 0xad, 0xbe, 0xef]);

0 commit comments

Comments
 (0)