fix: harden command auto-approval against inline JS false positives #11382
+69
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #11365. The merged fix narrowed the zsh process-substitution regex with a negative lookbehind
(?<![a-zA-Z0-9_]), but this still false-positives on inline JS expressions innode -ecommands where=(...)is preceded by characters like],), or}.Example command that was still blocked:
node -e "const fs=require('fs');const p=JSON.parse(fs.readFileSync('prd.json','utf8'));const allowed=new Set(['pending','in-progress','complete','blocked']);const bad=(p.items||[]).filter(i=>!allowed.has(i.status));console.log('statusCounts', (p.items||[]).reduce((a,i)=>(a[i.status]=(a[i.status]||0)+1,a),{}));if(bad.length){process.exit(2);}"The fragment `=(a[i.status]||0)` inside the JS reducer was matching because `]` is not in `[a-zA-Z0-9_]`.
Changes
1. `src/core/auto-approval/commands.ts` — Regex refinement
Changed zsh process-substitution detector from:
```
/(?<![a-zA-Z0-9_])=\([^)]+\/
/(?:(?<=^)|(?<=[\s;|&(<]))=([^)]+)/