Skip to content

Commit fb90dda

Browse files
committed
Do not count length when maxBuffer is Infinity
This reflects the changes in nodejs/node#43822
1 parent 31289a2 commit fb90dda

File tree

2 files changed

+52
-19
lines changed

2 files changed

+52
-19
lines changed

lib/foreground-exec-async.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,26 +109,29 @@ function execFileWithStdIO
109109
{
110110
if (encoding)
111111
stream.setEncoding(encoding);
112-
stream.on
113-
(
114-
'data',
115-
chunk =>
112+
const listener =
113+
maxBuffer === Infinity ?
114+
chunk =>
115+
{
116+
chunks.push(chunk);
117+
} :
118+
chunk =>
119+
{
120+
const encoding = stream.readableEncoding;
121+
const length = encoding ? Buffer.byteLength(chunk, encoding) : chunk.length;
122+
const available = maxBuffer - chunks.byteLength;
123+
if (length > available)
116124
{
117-
const encoding = stream.readableEncoding;
118-
const length = encoding ? Buffer.byteLength(chunk, encoding) : chunk.length;
119-
const available = maxBuffer - chunks.byteLength;
120-
if (length > available)
121-
{
122-
chunks.push(chunk.slice(0, available));
123-
error = new RangeError(`${name}, maxBuffer length exceeded`);
124-
error.code = 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER';
125-
kill();
126-
}
127-
else
128-
chunks.push(chunk);
129-
chunks.byteLength += length;
130-
},
131-
);
125+
chunks.push(chunk.slice(0, available));
126+
error = new RangeError(`${name}, maxBuffer length exceeded`);
127+
error.code = 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER';
128+
kill();
129+
}
130+
else
131+
chunks.push(chunk);
132+
chunks.byteLength += length;
133+
};
134+
stream.on('data', listener);
132135
}
133136
return chunks;
134137
}

test/exec.spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,21 @@ describe
249249
() => testMaxBuffer('stdout', 'ascii', 'l\'archiviazione C'),
250250
);
251251

252+
it
253+
(
254+
'on stdout with value `Infinity`',
255+
async () =>
256+
{
257+
const { stdout } =
258+
await c8js.exec
259+
(
260+
joinPath('test/fixtures/stdout-max-buffer-test.js'),
261+
{ maxBuffer: Infinity, silent: true, tempDirectory },
262+
);
263+
assert.equal(stdout, 'l\'archiviazione è riuscita\n');
264+
},
265+
);
266+
252267
it
253268
(
254269
'on stderr with `buffer` encoding',
@@ -272,6 +287,21 @@ describe
272287
'on stderr with `ascii` encoding',
273288
() => testMaxBuffer('stderr', 'ascii', 'es liegt eine StC'),
274289
);
290+
291+
it
292+
(
293+
'on stderr with value `Infinity`',
294+
async () =>
295+
{
296+
const { stderr } =
297+
await c8js.exec
298+
(
299+
joinPath('test/fixtures/stderr-max-buffer-test.js'),
300+
{ maxBuffer: Infinity, silent: true, tempDirectory },
301+
);
302+
assert.equal(stderr, 'es liegt eine Störung vor\n');
303+
},
304+
);
275305
},
276306
);
277307

0 commit comments

Comments
 (0)