From 08edf5320759670ef72235940a8e242704d6816f Mon Sep 17 00:00:00 2001 From: Harshitha KP Date: Fri, 6 Mar 2020 06:30:07 -0500 Subject: [PATCH] test: `buffer.write` with longer string scenario Make sure longer strings are written up to the buffer end Refs: https://github.com/nodejs/node/pull/32119 PR-URL: https://github.com/nodejs/node/pull/32123 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Ruben Bridgewater --- test/parallel/test-buffer-write.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/parallel/test-buffer-write.js b/test/parallel/test-buffer-write.js index 1f080add08451f..842b12c04c04db 100644 --- a/test/parallel/test-buffer-write.js +++ b/test/parallel/test-buffer-write.js @@ -90,6 +90,9 @@ for (let i = 1; i < 4; i++) { const z = Buffer.alloc(4, 0); assert.strictEqual(z.write('\u0001', 3, 'ucs2'), 0); assert.strictEqual(Buffer.compare(z, Buffer.alloc(4, 0)), 0); +// Make sure longer strings are written up to the buffer end. +assert.strictEqual(z.write('abcd', 2), 2); +assert.deepStrictEqual([...z], [0, 0, 0x61, 0x62]); // Large overrun could corrupt the process assert.strictEqual(Buffer.alloc(4)