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: validate options.shell and correctly enforce shell invocation in exec/execSync #56761

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Renegade334
Copy link
Contributor

Previously opened as #54623, and the PR description there is still valid. Unfortunately this was originally submitted while CI was blocked by the macos test platform issues, and never made it back to request-ci.

- narrow validation type to string (previously de facto not validated)
- ensure empty string is coerced to true
- add test cases for options.shell
@nodejs-github-bot nodejs-github-bot added child_process Issues and PRs related to the child_process subsystem. needs-ci PRs that need a full CI run. labels Jan 25, 2025
Copy link

codecov bot commented Jan 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.21%. Comparing base (bade7a1) to head (975a59e).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #56761      +/-   ##
==========================================
- Coverage   89.21%   89.21%   -0.01%     
==========================================
  Files         662      662              
  Lines      192124   192129       +5     
  Branches    36980    36976       -4     
==========================================
+ Hits       171404   171407       +3     
- Misses      13552    13558       +6     
+ Partials     7168     7164       -4     
Files with missing lines Coverage Δ
lib/child_process.js 97.74% <100.00%> (+0.01%) ⬆️

... and 21 files with indirect coverage changes

Comment on lines +203 to +204
}
options.shell ||= true;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why would we want to accept the empty string a valid value

Suggested change
}
options.shell ||= true;
} else {
options.shell = true;
}

Copy link
Contributor Author

@Renegade334 Renegade334 Jan 25, 2025

Choose a reason for hiding this comment

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

The sister functions spawn/execFile validate shell: '' as valid, and their behaviour then becomes the same as passing false or undefined.

This PR makes exec's behaviour the same as these, but the empty string needs to be coerced to true just the same as nullish values, otherwise the default shell won't be spawned (as per the logic outlined in the previous PR's description).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants