Fix quoting and escaping of operators, aliases and variable names #402
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.39) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 270 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.335
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #402"
general
weight: 0.35
ianthomas23
Summary
The tokenizer only handled backslash-newline: other escapes were left to variable expansion, and quoted text was still recognised as an operator. Quoted or escaped
;,|,&&,>and<<therefore acted as shell syntax, and escaped spaces and quotes did not work.This PR resolves escapes in the tokenizer and records quoted characters, so the parser and alias expansion can tell quoted text from syntax.
It is also groundwork for
$(command)support, which needs the tokenizer to know when\$(is escaped and to find the closing)across escapes and quotes.Behaviour changes
| Input | Before | After (matches bash) |
|---|---|---|
|
echo ";"|;treated as a separator; prints an empty line | prints;||
echo a;"echo"| single word;echo; printsa ;echo| runsecho a, thenecho||
echo "2>",echo "<<",echo \>| treated as a redirect / here document | printed as words ||
echo a\ b| two words,a\andb| one word,a b||
echo "a\"b"| quote left open, prompts for more input | printsa"b||
echo a\|,echo a\| waits for another line | runs ||
"ll", andllafter"a\|"or>\|| alias expanded | alias not expanded ||
A=x; echo $A""B| looks upAB| printsxB|Implementation
- A backslash removes itself and records the next character as quoted: any character outside quotes, and only
$, ``,"and\inside double quotes.&&- An operator token ends before a quoted or escaped word.
- A quoted operator never extends a redirect.
- Aliases only expand for unquoted names that follow an unquoted control operator.
- A newline after
or||no longer inserts a;token.
Parser: isSeparator-
, the pipe check,isRedirectTokenandisHeredocTokenignore quoted tokens.isCommandComplete-
decides from tokens instead of string suffixes, and reuses those tokens to parse.
Expansion: _expand- Escapes in tokens are already resolved, so
only removes backslashes for raw strings and here-document bodies._reference` ends a variable name at the start of any quoted section, including an empty one.-