Summary
The parse() function in shell-quote throws an uncaught error when encountering malformed shell variable substitutions. This happens with patterns like ${result (missing closing brace) or other invalid variable substitution syntax.
Environment
- shell-quote version: 1.8.1
- Node.js version: v22.17.0
- OS: Linux/macOS/Windows
Current Behavior
When parsing commands with malformed variable substitutions, shell-quote throws an error:
Error: Bad substitution: result
at parseEnvVar (/node_modules/shell-quote/parse.js:128:12)
at <anonymous> (/node_modules/shell-quote/parse.js:189:12)
at Array.map (<anonymous>)
at parseInternal (/node_modules/shell-quote/parse.js:89:17)
at Object.parse (/node_modules/shell-quote/parse.js:207:15)
Expected Behavior
The parser should either:
- Return the malformed syntax as-is (treating it as a literal string)
- Return an error object that can be handled gracefully
- Provide an option to handle parsing errors without throwing
Steps to Reproduce
const { parse } = require('shell-quote');
// These all throw "Bad substitution" errors:
parse('echo ${result'); // Error: Bad substitution: result
parse('${VAR'); // Error: Bad substitution: VAR
parse('test ${a ${b'); // Error: Bad substitution: a ${b
parse('command ${'); // Error: Bad substitution:
parse('ls ${PATH }'); // Error: Bad substitution: PATH }
Additional Context
This is particularly problematic in interactive applications where users might type commands incrementally or make syntax errors. The current behavior makes it impossible to provide helpful error messages or syntax highlighting for malformed commands.
Summary
The
parse()function in shell-quote throws an uncaught error when encountering malformed shell variable substitutions. This happens with patterns like${result(missing closing brace) or other invalid variable substitution syntax.Environment
Current Behavior
When parsing commands with malformed variable substitutions, shell-quote throws an error:
Expected Behavior
The parser should either:
Steps to Reproduce
Additional Context
This is particularly problematic in interactive applications where users might type commands incrementally or make syntax errors. The current behavior makes it impossible to provide helpful error messages or syntax highlighting for malformed commands.