Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,11 @@ function _copyActual(source, target, targetStart, sourceStart, sourceEnd) {
if (nb <= 0)
return 0;

_copy(source, target, targetStart, sourceStart, nb);
if (sourceStart === 0 && nb === sourceLen) {
TypedArrayPrototypeSet(target, source, targetStart);
} else {
_copy(source, target, targetStart, sourceStart, nb);
}

return nb;
}
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-buffer-concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ assert.throws(() => {
const random10 = common.hasCrypto ?
require('crypto').randomBytes(10) :
Buffer.alloc(10, 1);
const derived18 = Buffer.alloc(18);
for (let i = 0, j = 0; i < 18; i++) {
if (i < 10)
derived18[i] = random10[i];
else
derived18[i] = random10[j++];
}
const empty = Buffer.alloc(0);

assert.notDeepStrictEqual(random10, empty);
Expand All @@ -85,6 +92,7 @@ assert.deepStrictEqual(Buffer.concat([], 100), empty);
assert.deepStrictEqual(Buffer.concat([random10], 0), empty);
assert.deepStrictEqual(Buffer.concat([random10], 10), random10);
assert.deepStrictEqual(Buffer.concat([random10, random10], 10), random10);
assert.deepStrictEqual(Buffer.concat([random10, random10], 18), derived18);
assert.deepStrictEqual(Buffer.concat([empty, random10]), random10);
assert.deepStrictEqual(Buffer.concat([random10, empty, empty]), random10);

Expand Down
Loading