Repository navigation
fix(standalone): shell command parsing for operators, quotes, and nod… - #11631
VishalRaut2106 wants to merge 2 commits into
Conversation
…e -e Fixes firebase#11627 where standalone binary incorrectly handles: - Shell operators (&&, ||, |, ;) - Quotes in arguments ('x y') - node -e 'console.log(1)' syntax Added needsShellProcessing detection function and improved command parsing to handle shell syntax properly. When shell operators or complex syntax is detected, uses shell: true mode for child_process.spawn. Otherwise uses improved parsing that preserves quoted strings.
There was a problem hiding this comment.
Code Review
This pull request updates standalone/runtime.js to intelligently parse commands and determine whether they require shell processing before spawning. For commands not requiring a shell, a custom parser is introduced to split arguments while respecting quotes. The review feedback highlights critical issues with this implementation: the custom parser fails to strip quotes and handle empty quoted arguments, and it is currently dead code because the shell-detection regex routes all quoted commands to the shell path anyway. Additionally, the feedback notes that spawning non-Node commands with shell: false will break batch files on Windows, and commands without arguments may incorrectly pass an empty string argument.
Fix for Issue #11627: Standalone binary shell command parsing
Problem
The standalone Firebase CLI binary incorrectly handles shell commands when they contain:
&&,||,|,;)"x y")node -e "console.log(1)"syntaxRoot Cause
The
Script_ShellJSfunction instandalone/runtime.jsused naive string splitting:This approach fails because:
node a.js && node b.js→['node', 'a.js', '&&', 'node', 'b.js'](&& passed as arg, b.js never runs)node -e "console.log(1)"→['node', '-e', '"console.log(1)"'](-e treated as script file)node a.js "x y"→['node', 'a.js', '"x', 'y"'](quotes split)Solution
Implemented intelligent command parsing with two modes:
Shell Mode: For commands with shell operators, quotes, or
node -esyntaxchild_process.spawn(cmd, { shell: true })Parsed Mode: For simple commands
child_process.fork()for Node scriptsImplementation Details
Key Functions Added:
needsShellProcessing(cmd): Detects if command requires shell modeChanges Made:
split(" ")with intelligent parsing&&,||,|,;,<,>,$)node -eandnode --evalsyntaxTesting
The fix was tested with the exact reproduction cases from issue #11627:
Test Cases Verified:
node a.js && node b.js- Both scripts run sequentiallynode -e "console.log(1)"- Node eval works correctlynode a.js "x y"- Quotes preserved as single argumentAdditional Tests:
node script.js- Simple command still worksnpm install- Non-Node commands still workecho hello- Simple shell commands workImpact
node -ein postinstall scripts (e.g., core-js)Files Modified
standalone/runtime.js- UpdatedScript_ShellJSfunctionHow to Test
npm run buildRelated Issues
This fix resolves #11627 and may help with related issues where shell scripting
in npm scripts fails with the standalone Firebase CLI binary.