Skip to content

fix(shell): preserve quoted case-modified arguments - #784

Open
Prasad-178 wants to merge 3 commits into
vercel-labs:mainfrom
Prasad-178:fix/quoted-case-modified-arguments
Open

Prasad-178 wants to merge 3 commits into
vercel-labs:mainfrom
Prasad-178:fix/quoted-case-modified-arguments

Conversation

@Prasad-178

@Prasad-178 Prasad-178 commented Nov 30, 2026 •

Copy link
Copy Markdown

Addresses item 4 of #758.

Apply case modification per value for quoted array and positional argument expansions. The @ forms preserve argument boundaries and the * forms join using the first character of IFS. With adjacent text inside the quote, attach it to the first and last arguments. Single-character case operators with an explicit pattern check the leading character.

Verified 18 cases directly against GNU Bash 5.3.9. The regression suite also checks that aggregate output still respects the string limit. Interpreter and adjacent limit suites passed with 1,379 passed and one skipped. Typecheck and changed-file lint passed.

A clean checkout also passed the repository lint, build, and all 1,059 comparison tests.

The full local unit run had 15,377 passes, 98 skips, and four filesystem test failures. All four failures also reproduced on the untouched upstream commit on this machine.

@vercel

vercel Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

@Prasad-178 is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

@auto-maintain

auto-maintain Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

🤖 auto-maintain review

Automated, advisory triage for @Prasad-178's PR. Facts below are read from the GitHub API.

Check Result
Author's merged PRs (this repo) 0 — ⚠️ first-time contributor
Account established ✅ (age 1793d · 20 followers · 75 public repos)
Commits signed/verified ✅ 3/3
Changeset included ✅ (.changeset/quoted-case-arguments.md)

Review panel: 🟡 medium highest severity

just-bash maintainer code review: 🟡 medium

Quoted case modification works for the tested simple forms, but still loses argument boundaries when composed with array slicing or brace expansion.

  • packages/just-bash/src/interpreter/expansion/word-glob-expansion.ts:667 — Quoted list-producing operations other than bare/case-modified @/* are collapsed to a scalar. For example, with a=(ab cd), b=(ef gh), "${a[@]:0:2}${b[@]^}" yields two arguments instead of Bash's three because the slice is expanded through scalar expandPart().
  • packages/just-bash/src/interpreter/expansion/word-glob-expansion.ts:149 — Multiple brace results return before the case-modified list handler runs. Thus {x,y}"${a[@]^}" with a=(ab cd) collapses each array expansion into one argument instead of producing xAb, Cd, yAb, Cd.

General code review: 🟡 medium

The new stitching path mishandles quoted empty contributions and tilde-expanded prefixes, producing incorrect argument boundaries.

  • packages/just-bash/src/interpreter/expansion/word-glob-expansion.ts:668 — Empty quoted siblings are discarded here. With `a=(); x=; set -- "$x${a[@]^}"`, Bash retains one empty argument, but this path skips `$x` because its value is empty and returns zero arguments.
  • packages/just-bash/src/interpreter/expansion/word-glob-expansion.ts:682 — The generic branch applies IFS splitting to tilde expansion, whose result Bash treats as quoted. For example, with `HOME='/tmp/a b'; a=(x)`, `~"${a[@]^}"` should be one `/tmp/a bX` argument but becomes `/tmp/a` and `bX`. TildeExpansion needs protected-fragment handling.

Adversarial security: 🟡 medium

The new stitching path can violate shell argument boundaries around unquoted IFS-split expansions.

  • packages/just-bash/src/interpreter/expansion/word-glob-expansion.ts:683 — IFS boundary metadata is discarded here, then append() unconditionally joins the next first field to the previous word. For example, an unquoted expansion ending in an IFS delimiter immediately before a quoted case-modified array is merged with its first element instead of remaining a separate argument. This corrupts argv boundaries and can enable argument/option confusion when expansion values are attacker-controlled; use splitByIfsForExpansionEx and preserve its leading/trailing delimiter flags.

Adversarial security (second opinion): 🟡 medium

No malicious or security-relevant behavior found — the change is confined to shell case-modification semantics with limits and glob handling preserved; one argument-boundary defect in the new stitching path should be fixed or consciously accepted before merge.

  • packages/just-bash/src/interpreter/expansion/word-glob-expansion.ts:683 — In the new `expandQuotedCaseModification` path, unquoted splittable parts are split with `splitByIfsForExpansion`, which discards the leading/trailing IFS delimiter information that `smartWordSplit` tracks via `splitByIfsForExpansionEx`. Because `append()` unconditionally stitches a split result's first element onto the previous word, a delimiter at the boundary silently merges two arguments: with `a=(ab cd); v=" x"`, `set -- "${a[@]^}"$v` yields `Ab`, `Cdx` instead of bash's `Ab`, `Cd`, `x` (and symmetrically `$v"${a[@]^}"` with `v="x "` yields `xAb`, `Cd`). This is the exact argument-boundary class of bug the PR intends to fix, now reintroduced for words that mix an unquoted expansion with a quoted case-modified list.

Standard Bash and host portability: 🟡 medium

The quoted case fix does not compose correctly with brace expansion or adjacent unquoted argument-list expansions.

  • packages/just-bash/src/interpreter/expansion/word-glob-expansion.ts:149 — Brace expansion returns before the new list-aware case path. `{x,y}"${a[@]^}"` with `a=(ab cd)` becomes two flattened arguments instead of Bash's four (`xAb`, `Cd`, `yAb`, `Cd`).
  • packages/just-bash/src/interpreter/expansion/word-glob-expansion.ts:672 — When this handler is active, an adjacent unquoted `${b[@]}` or `$@` is expanded to one string before IFS splitting, losing element boundaries. With `IFS=:` and `b=("x:y" z)`, `${b[@]}"${a[@]^}"` merges `z` into the preceding field instead of producing Bash's separate `zAb` argument.

Posted by auto-maintain. This automated code review is advisory; a human maintainer makes the call.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant