-
Notifications
You must be signed in to change notification settings - Fork 16.5k
fix: 避免 && 短路时误用未执行命令的退出码语义 #1347
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
Open
ai-yang
wants to merge
1
commit into
claude-code-best:main
Choose a base branch
from
ai-yang:audit/fix-bash-command-semantics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+43
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
Repository: claude-code-best/claude-code
Length of output: 11736
🏁 Script executed:
Repository: claude-code-best/claude-code
Length of output: 50384
🏁 Script executed:
Repository: claude-code-best/claude-code
Length of output: 31607
🏁 Script executed:
Repository: claude-code-best/claude-code
Length of output: 17098
🌐 Web query:
shell-quote 1.8.3 parse "Bad substitution" ${var + expr}💡 Result:
The "Bad substitution" error in the shell-quote library—including version 1.8.3 and others—occurs because the library's internal tokenizer is not a full-featured Bash interpreter [1][2][3]. The library only supports simple parameter expansion in the format of
$VARNAMEor${VARNAME}[2][4][5]. It does not support complex Bash features such as: * Arithmetic expansion (e.g.,$((...))) [1][5] * Command substitution (e.g.,$(...)) [1][5] * Parameter expansion with modifiers (e.g.,${var:-default},${var/a/b}) [1][5] * Array indexing (e.g.,${arr[i]}) [1][6] The specific error "Bad substitution" is triggered when the parser encounters whitespace inside a${...}block or other complex syntax it cannot resolve [1][2][5]. Because the library uses a simplified, regex-based tokenizer, expressions like${var + expr}contain characters (such as spaces or operators) that the parser does not recognize as valid for a simple variable name, leading it to throw an error rather than ignoring or evaluating the expression [1][2][7]. If your application requires evaluation of complex Bash syntax, the recommended approach is to avoid using shell-quote for parsing such commands and instead execute the commands directly via a shell (e.g., using Node.jschild_process.execFileorspawn) [1]. If you must use the library for validation or sanitization, common workarounds in existing projects include catching the "Bad substitution" error and treating the entire command string as an opaque block, or skipping the parser for complex commands [8][7].Citations:
🏁 Script executed:
Repository: claude-code-best/claude-code
Length of output: 6641
Handle parse-fallback commands before selecting command semantics.
On parse failure,
splitCommandWithOperatorsreturns the complete command as one element. Forrg ${var + expr} && echo, the&&check misses the operator, andsplitCommand_DEPRECATEDselectsrg. Exit code 1 is then treated as “No matches found” instead of a command failure. Propagate parse status or a quote-aware ambiguity signal, and add a regression test.🤖 Prompt for AI Agents