| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 90a64ab commit ac5fa2c
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -147,8 +147,9 @@ changes: | |||
| 147 | 147 | `'/bin/sh'` on UNIX, `process.env.ComSpec` on Windows. | |
| 148 | 148 | * `timeout` {number} **Default:** `0` | |
| 149 | 149 | * `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or | |
| 150 | - stderr. If exceeded, the child process is terminated. See caveat at | ||
| 151 | - [`maxBuffer` and Unicode][]. **Default:** `200 * 1024`. | ||
| 150 | + stderr. If exceeded, the child process is terminated and any output is | ||
| 151 | + truncated. See caveat at [`maxBuffer` and Unicode][]. | ||
| 152 | + **Default:** `200 * 1024`. | ||
| 152 | 153 | * `killSignal` {string|integer} **Default:** `'SIGTERM'` | |
| 153 | 154 | * `uid` {number} Sets the user identity of the process (see setuid(2)). | |
| 154 | 155 | * `gid` {number} Sets the group identity of the process (see setgid(2)). | |
@@ -245,8 +246,9 @@ changes: | |||
| 245 | 246 | * `encoding` {string} **Default:** `'utf8'` | |
| 246 | 247 | * `timeout` {number} **Default:** `0` | |
| 247 | 248 | * `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or | |
| 248 | - stderr. If exceeded, the child process is terminated. See caveat at | ||
| 249 | - [`maxBuffer` and Unicode][]. **Default:** `200 * 1024`. | ||
| 249 | + stderr. If exceeded, the child process is terminated and any output is | ||
| 250 | + truncated. See caveat at [`maxBuffer` and Unicode][]. | ||
| 251 | + **Default:** `200 * 1024`. | ||
| 250 | 252 | * `killSignal` {string|integer} **Default:** `'SIGTERM'` | |
| 251 | 253 | * `uid` {number} Sets the user identity of the process (see setuid(2)). | |
| 252 | 254 | * `gid` {number} Sets the group identity of the process (see setgid(2)). | |
@@ -779,8 +781,9 @@ changes: | |||
| 779 | 781 | * `killSignal` {string|integer} The signal value to be used when the spawned | |
| 780 | 782 | process will be killed. **Default:** `'SIGTERM'`. | |
| 781 | 783 | * `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or | |
| 782 | - stderr. If exceeded, the child process is terminated. See caveat at | ||
| 783 | - [`maxBuffer` and Unicode][]. **Default:** `200 * 1024`. | ||
| 784 | + stderr. If exceeded, the child process is terminated and any output is | ||
| 785 | + truncated. See caveat at [`maxBuffer` and Unicode][]. | ||
| 786 | + **Default:** `200 * 1024`. | ||
| 784 | 787 | * `encoding` {string} The encoding used for all stdio inputs and outputs. | |
| 785 | 788 | **Default:** `'buffer'`. | |
| 786 | 789 | * `windowsHide` {boolean} Hide the subprocess console window that would | |
@@ -842,8 +845,9 @@ changes: | |||
| 842 | 845 | * `killSignal` {string|integer} The signal value to be used when the spawned | |
| 843 | 846 | process will be killed. **Default:** `'SIGTERM'`. | |
| 844 | 847 | * `maxBuffer` {number} Largest amount of data in bytes allowed on stdout or | |
| 845 | - stderr. If exceeded, the child process is terminated. See caveat at | ||
| 846 | - [`maxBuffer` and Unicode][]. **Default:** `200 * 1024`. | ||
| 848 | + stderr. If exceeded, the child process is terminated and any output is | ||
| 849 | + truncated. See caveat at [`maxBuffer` and Unicode][]. | ||
| 850 | + **Default:** `200 * 1024`. | ||
| 847 | 851 | * `encoding` {string} The encoding used for all stdio inputs and outputs. | |
| 848 | 852 | **Default:** `'buffer'`. | |
| 849 | 853 | * `shell` {boolean|string} If `true`, runs `command` inside of a shell. Uses | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -345,9 +345,15 @@ exports.execFile = function execFile(file /* , args, options, callback */) { | |||
| 345 | 345 | ||
| 346 | 346 | child.stdout.on('data', function onChildStdout(chunk) { | |
| 347 | 347 | var encoding = child.stdout._readableState.encoding; | |
| 348 | - stdoutLen += encoding ? Buffer.byteLength(chunk, encoding) : chunk.length; | ||
| 348 | + const length = encoding ? | ||
| 349 | + Buffer.byteLength(chunk, encoding) : | ||
| 350 | + chunk.length; | ||
| 351 | + stdoutLen += length; | ||
| 349 | 352 | ||
| 350 | 353 | if (stdoutLen > options.maxBuffer) { | |
| 354 | + const truncatedLen = options.maxBuffer - (stdoutLen - length); | ||
| 355 | + _stdout.push(chunk.slice(0, truncatedLen)); | ||
| 356 | + | ||
| 351 | 357 | ex = new ERR_CHILD_PROCESS_STDIO_MAXBUFFER('stdout'); | |
| 352 | 358 | kill(); | |
| 353 | 359 | } else { | |
@@ -362,9 +368,15 @@ exports.execFile = function execFile(file /* , args, options, callback */) { | |||
| 362 | 368 | ||
| 363 | 369 | child.stderr.on('data', function onChildStderr(chunk) { | |
| 364 | 370 | var encoding = child.stderr._readableState.encoding; | |
| 365 | - stderrLen += encoding ? Buffer.byteLength(chunk, encoding) : chunk.length; | ||
| 371 | + const length = encoding ? | ||
| 372 | + Buffer.byteLength(chunk, encoding) : | ||
| 373 | + chunk.length; | ||
| 374 | + stderrLen += length; | ||
| 366 | 375 | ||
| 367 | 376 | if (stderrLen > options.maxBuffer) { | |
| 377 | + const truncatedLen = options.maxBuffer - (stderrLen - length); | ||
| 378 | + _stderr.push(chunk.slice(0, truncatedLen)); | ||
| 379 | + | ||
| 368 | 380 | ex = new ERR_CHILD_PROCESS_STDIO_MAXBUFFER('stderr'); | |
| 369 | 381 | kill(); | |
| 370 | 382 | } else { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,13 +22,13 @@ function runChecks(err, stdio, streamName, expected) { | |||
| 22 | 22 | } | |
| 23 | 23 | ||
| 24 | 24 | { | |
| 25 | - const cmd = 'echo "hello world"'; | ||
| 25 | + const cmd = 'echo hello world'; | ||
| 26 | 26 | ||
| 27 | 27 | cp.exec( | |
| 28 | 28 | cmd, | |
| 29 | 29 | { maxBuffer: 5 }, | |
| 30 | 30 | common.mustCall((err, stdout, stderr) => { | |
| 31 | - runChecks(err, { stdout, stderr }, 'stdout', ''); | ||
| 31 | + runChecks(err, { stdout, stderr }, 'stdout', 'hello'); | ||
| 32 | 32 | }) | |
| 33 | 33 | ); | |
| 34 | 34 | } | |
@@ -42,7 +42,7 @@ const unicode = '中文测试'; // length = 4, byte length = 12 | |||
| 42 | 42 | cmd, | |
| 43 | 43 | { maxBuffer: 10 }, | |
| 44 | 44 | common.mustCall((err, stdout, stderr) => { | |
| 45 | - runChecks(err, { stdout, stderr }, 'stdout', ''); | ||
| 45 | + runChecks(err, { stdout, stderr }, 'stdout', '中文测试\n'); | ||
| 46 | 46 | }) | |
| 47 | 47 | ); | |
| 48 | 48 | } | |
@@ -54,7 +54,7 @@ const unicode = '中文测试'; // length = 4, byte length = 12 | |||
| 54 | 54 | cmd, | |
| 55 | 55 | { maxBuffer: 3 }, | |
| 56 | 56 | common.mustCall((err, stdout, stderr) => { | |
| 57 | - runChecks(err, { stdout, stderr }, 'stderr', ''); | ||
| 57 | + runChecks(err, { stdout, stderr }, 'stderr', '中文测'); | ||
| 58 | 58 | }) | |
| 59 | 59 | ); | |
| 60 | 60 | } | |
@@ -66,7 +66,7 @@ const unicode = '中文测试'; // length = 4, byte length = 12 | |||
| 66 | 66 | cmd, | |
| 67 | 67 | { encoding: null, maxBuffer: 10 }, | |
| 68 | 68 | common.mustCall((err, stdout, stderr) => { | |
| 69 | - runChecks(err, { stdout, stderr }, 'stdout', ''); | ||
| 69 | + runChecks(err, { stdout, stderr }, 'stdout', '中文测试\n'); | ||
| 70 | 70 | }) | |
| 71 | 71 | ); | |
| 72 | 72 | ||
@@ -80,9 +80,22 @@ const unicode = '中文测试'; // length = 4, byte length = 12 | |||
| 80 | 80 | cmd, | |
| 81 | 81 | { encoding: null, maxBuffer: 3 }, | |
| 82 | 82 | common.mustCall((err, stdout, stderr) => { | |
| 83 | - runChecks(err, { stdout, stderr }, 'stderr', ''); | ||
| 83 | + runChecks(err, { stdout, stderr }, 'stderr', '中文测'); | ||
| 84 | 84 | }) | |
| 85 | 85 | ); | |
| 86 | 86 | ||
| 87 | 87 | child.stderr.setEncoding('utf-8'); | |
| 88 | 88 | } | |
| 89 | + | ||
| 90 | + { | ||
| 91 | + const cmd = `"${process.execPath}" -e "console.error('${unicode}');"`; | ||
| 92 | + | ||
| 93 | + cp.exec( | ||
| 94 | + cmd, | ||
| 95 | + { encoding: null, maxBuffer: 5 }, | ||
| 96 | + common.mustCall((err, stdout, stderr) => { | ||
| 97 | + const buf = Buffer.from(unicode).slice(0, 5); | ||
| 98 | + runChecks(err, { stdout, stderr }, 'stderr', buf); | ||
| 99 | + }) | ||
| 100 | + ); | ||
| 101 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments