← Back to Pull requests

Fix quoting and escaping of operators, aliases and variable names #402

Closed
unknown closed this pull request without merging on Dec 02, 2026 14:39 UTC
View on GitHub
unknown unknown commented on Dec 01, 2026 09:36 UTC
Author

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; prints a ;echo | runs echo a, then echo |
| echo "2>", echo "<<", echo \> | treated as a redirect / here document | printed as words |
| echo a\ b | two words, a\ and b | one word, a b |
| echo "a\"b" | quote left open, prompts for more input | prints a"b |
| echo a\|, echo a\ | waits for another line | runs |
| "ll", and ll after "a\|" or >\| | alias expanded | alias not expanded |
| A=x; echo $A""B | looks up AB | prints xB |

Implementation

  • Tokenizer:

  • - 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, isRedirectToken and isHeredocToken ignore quoted tokens.
    -
    isCommandComplete decides from tokens instead of string suffixes, and reuses those tokens to parse.
  • Expansion:

  • - Escapes in tokens are already resolved, so
    _expand 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.

    Diff: 270 lines (+202 / -68) across 3 files Reviewer: ianthomas23 Review duration: 1743m
    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
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.4% (MEDIUM) · Higher = larger blast radius
    39.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.6% · Safe to merge
    15.6%