Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

child_process: make the maxBuffer correct with unicode #1902

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
11 changes: 3 additions & 8 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ exports.execFile = function(file /*, args, options, callback*/) {
_stderr = [];
encoding = null;
}
var stdoutLen = 0;
var stderrLen = 0;

var killed = false;
var exited = false;
var timeoutId;
Expand Down Expand Up @@ -260,9 +259,7 @@ exports.execFile = function(file /*, args, options, callback*/) {
child.stdout.setEncoding(encoding);

child.stdout.addListener('data', function(chunk) {
stdoutLen += chunk.length;

if (stdoutLen > options.maxBuffer) {
if (child.stdout.bytesRead > options.maxBuffer) {
ex = new Error('stdout maxBuffer exceeded');
kill();
} else {
Expand All @@ -279,9 +276,7 @@ exports.execFile = function(file /*, args, options, callback*/) {
child.stderr.setEncoding(encoding);

child.stderr.addListener('data', function(chunk) {
stderrLen += chunk.length;

if (stderrLen > options.maxBuffer) {
if (child.stderr.bytesRead > options.maxBuffer) {
ex = new Error('stderr maxBuffer exceeded');
kill();
} else {
Expand Down
19 changes: 15 additions & 4 deletions test/parallel/test-exec-max-buffer.js
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this because echo doesn't exist on windows? Is there anything we can do to test windows?

I'm not terribly comfortable with this kind of testing. :s

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the spawn execute echo with unicode has unexpected behavior.

发自我的 iPhone

在 2015年7月7日,上午1:11,Jeremiah Senkpiel [email protected] 写道:

In test/parallel/test-exec-max-buffer.js:

@@ -9,3 +9,14 @@ exec(cmd, { maxBuffer: 5 }, function(err, stdout, stderr) {
assert.ok(err);
assert.ok(/maxBuffer/.test(err.message));
});
+
+if (!common.isWindows) {
Is this because echo doesn't exist on windows? Is there anything we can do to test windows?

I'm not terribly comfortable with this kind of testing. :s


Reply to this email directly or view it on GitHub.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

echo does exist im cmd, so should probably work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fishrock123 the windows has an unrelated edge issue here. when echo unicode.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would copy file-in-fixtures-directory con work? (cat on UNIX.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try @bnoordhuis suggestion? If that doesn't work, you should add a comment on why this is skipped on Windows.

const unicode = '中文测试'; // length: 12
exec('echo ' + unicode, {
encoding: 'utf8',
maxBuffer: 10
}, common.mustCall(function(err, stdout, stderr) {
assert.strictEqual(err.message, 'stdout maxBuffer exceeded');
}));
}