| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent fd05b0b commit 6a08535
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -190,12 +190,12 @@ exports.execFile = function(file /*, args, options, callback*/) { | |||
| 190 | 190 | // merge chunks | |
| 191 | 191 | var stdout; | |
| 192 | 192 | var stderr; | |
| 193 | - if (!encoding) { | ||
| 194 | - stdout = Buffer.concat(_stdout); | ||
| 195 | - stderr = Buffer.concat(_stderr); | ||
| 196 | - } else { | ||
| 193 | + if (encoding) { | ||
| 197 | 194 | stdout = _stdout; | |
| 198 | 195 | stderr = _stderr; | |
| 196 | + } else { | ||
| 197 | + stdout = Buffer.concat(_stdout); | ||
| 198 | + stderr = Buffer.concat(_stderr); | ||
| 199 | 199 | } | |
| 200 | 200 | ||
| 201 | 201 | if (ex) { | |
@@ -260,16 +260,16 @@ exports.execFile = function(file /*, args, options, callback*/) { | |||
| 260 | 260 | child.stdout.setEncoding(encoding); | |
| 261 | 261 | ||
| 262 | 262 | child.stdout.addListener('data', function(chunk) { | |
| 263 | - stdoutLen += chunk.length; | ||
| 263 | + stdoutLen += encoding ? Buffer.byteLength(chunk, encoding) : chunk.length; | ||
| 264 | 264 | ||
| 265 | 265 | if (stdoutLen > options.maxBuffer) { | |
| 266 | 266 | ex = new Error('stdout maxBuffer exceeded'); | |
| 267 | 267 | kill(); | |
| 268 | 268 | } else { | |
| 269 | - if (!encoding) | ||
| 270 | - _stdout.push(chunk); | ||
| 271 | - else | ||
| 269 | + if (encoding) | ||
| 272 | 270 | _stdout += chunk; | |
| 271 | + else | ||
| 272 | + _stdout.push(chunk); | ||
| 273 | 273 | } | |
| 274 | 274 | }); | |
| 275 | 275 | } | |
@@ -279,16 +279,16 @@ exports.execFile = function(file /*, args, options, callback*/) { | |||
| 279 | 279 | child.stderr.setEncoding(encoding); | |
| 280 | 280 | ||
| 281 | 281 | child.stderr.addListener('data', function(chunk) { | |
| 282 | - stderrLen += chunk.length; | ||
| 282 | + stderrLen += encoding ? Buffer.byteLength(chunk, encoding) : chunk.length; | ||
| 283 | 283 | ||
| 284 | 284 | if (stderrLen > options.maxBuffer) { | |
| 285 | 285 | ex = new Error('stderr maxBuffer exceeded'); | |
| 286 | 286 | kill(); | |
| 287 | 287 | } else { | |
| 288 | - if (!encoding) | ||
| 289 | - _stderr.push(chunk); | ||
| 290 | - else | ||
| 288 | + if (encoding) | ||
| 291 | 289 | _stderr += chunk; | |
| 290 | + else | ||
| 291 | + _stderr.push(chunk); | ||
| 292 | 292 | } | |
| 293 | 293 | }); | |
| 294 | 294 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,31 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const cp = require('child_process'); | ||
| 5 | + | ||
| 6 | + function checkFactory(streamName) { | ||
| 7 | + return common.mustCall((err) => { | ||
| 8 | + const message = `${streamName} maxBuffer exceeded`; | ||
| 9 | + assert.strictEqual(err.message, message); | ||
| 10 | + }); | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + { | ||
| 14 | + const cmd = 'echo "hello world"'; | ||
| 15 | + | ||
| 16 | + cp.exec(cmd, { maxBuffer: 5 }, checkFactory('stdout')); | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + const unicode = '中文测试'; // length = 4, byte length = 12 | ||
| 20 | + | ||
| 21 | + { | ||
| 22 | + const cmd = `"${process.execPath}" -e "console.log('${unicode}');"`; | ||
| 23 | + | ||
| 24 | + cp.exec(cmd, {maxBuffer: 10}, checkFactory('stdout')); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + { | ||
| 28 | + const cmd = `"${process.execPath}" -e "console.('${unicode}');"`; | ||
| 29 | + | ||
| 30 | + cp.exec(cmd, {maxBuffer: 10}, checkFactory('stderr')); | ||
| 31 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,13 +4,20 @@ const common = require('../common'); | |||
| 4 | 4 | const assert = require('assert'); | |
| 5 | 5 | const exec = require('child_process').exec; | |
| 6 | 6 | ||
| 7 | - const expectedCalls = 2; | ||
| 8 | - | ||
| 9 | - const cb = common.mustCall((data) => { | ||
| 10 | - assert.strictEqual(typeof data, 'string'); | ||
| 11 | - }, expectedCalls); | ||
| 7 | + var stdoutCalls = 0; | ||
| 8 | + var stderrCalls = 0; | ||
| 12 | 9 | ||
| 13 | 10 | const command = common.isWindows ? 'dir' : 'ls'; | |
| 14 | - exec(command).stdout.on('data', cb); | ||
| 11 | + exec(command).stdout.on('data', (data) => { | ||
| 12 | + stdoutCalls += 1; | ||
| 13 | + }); | ||
| 14 | + | ||
| 15 | + exec('fhqwhgads').stderr.on('data', (data) => { | ||
| 16 | + assert.strictEqual(typeof data, 'string'); | ||
| 17 | + stderrCalls += 1; | ||
| 18 | + }); | ||
| 15 | 19 | ||
| 16 | - exec('fhqwhgads').stderr.on('data', cb); | ||
| 20 | + process.on('exit', () => { | ||
| 21 | + assert(stdoutCalls > 0); | ||
| 22 | + assert(stderrCalls > 0); | ||
| 23 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments