You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve shell quote handling with proper nested quote support (#217)
## Summary
Replace `unquote_str` with `brush_parser::word::parse` for context-aware
shell unquoting. The old function stripped all quote characters
uniformly, breaking commands with nested quotes.
## Example
A `prepare` script like:
```json
{
"prepare": "node -e \"const v = parseInt(process.versions.node, 10); if (v >= 20) require('child_process').execSync('vp config', {stdio: 'inherit'});\""
}
```
Was parsed incorrectly because `unquote_str` stripped the single quotes
inside the double-quoted string:
```diff
- require(child_process).execSync(vp config, {stdio: inherit});
+ require('child_process').execSync('vp config', {stdio: 'inherit'});
```
## Test plan
- [x] `cargo test -p vite_shell` — all 7 tests pass
- [x] `test_unquote_preserves_nested_quotes` — single quotes in double
quotes, double quotes in single quotes, escape sequences
- [x] `test_flatten_pieces_recursion` — recursive flattening through
`word::parse`, bail on `$VAR` and `$(cmd)`
- [x] `test_parse_urllib_prepare` — real-world prepare script with
nested quotes
https://claude.ai/code/session_01SoJXo78ET9sowKTSdAuFAg
---------
Co-authored-by: Claude <noreply@anthropic.com>
let cmd = r#"node -e "const v = parseInt(process.versions.node, 10); if (v >= 20) require('child_process').execSync('vp config', {stdio: 'inherit'});""#;
290
+
let result = try_parse_as_and_list(cmd);
291
+
let(parsed, _) = &result.as_ref().unwrap()[0];
292
+
// Single quotes inside double quotes must be preserved as literal characters
293
+
assert_eq!(
294
+
parsed.args[1].as_str(),
295
+
"const v = parseInt(process.versions.node, 10); if (v >= 20) require('child_process').execSync('vp config', {stdio: 'inherit'});"
0 commit comments