-
Notifications
You must be signed in to change notification settings - Fork 30.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
child_process: make the maxBuffer correct with unicode
The maxLen just caculate the string length, but to unicode string, the string size is less than buffer size.
- Loading branch information
1 parent
83d2b77
commit 937452c
Showing
2 changed files
with
18 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,22 @@ | ||
'use strict'; | ||
require('../common'); | ||
var exec = require('child_process').exec; | ||
var assert = require('assert'); | ||
|
||
var cmd = 'echo "hello world"'; | ||
const common = require('../common'); | ||
const exec = require('child_process').exec; | ||
const assert = require('assert'); | ||
|
||
const cmd = 'echo "hello world"'; | ||
|
||
exec(cmd, { maxBuffer: 5 }, function(err, stdout, stderr) { | ||
assert.ok(err); | ||
assert.ok(/maxBuffer/.test(err.message)); | ||
}); | ||
|
||
if (!common.isWindows) { | ||
const unicode = '中文测试'; // length: 12 | ||
exec('echo ' + unicode, { | ||
encoding: 'utf8', | ||
maxBuffer: 10 | ||
}, common.mustCall(function(err, stdout, stderr) { | ||
assert.strictEqual(err.message, 'stdout maxBuffer exceeded'); | ||
})); | ||
} |