fix(#4276): read the quoting, not just the digits, before eating an IO number (#4420)

POSIX recognizes an IO number only when the digit run is unquoted, but
tokenize()'s redirection branch tested `cur` — the token's characters — and
never `curMask`, their quoting. `"2"` and `2` were indistinguishable to it,
so a correct `gsd_run query commit ... --files "2">out` had its value
consumed as an IO number and scored as an unscoped invocation: the #2269
guard reddening on documentation that was right.

The mask was already maintained in the same loop and thrown away on this
branch. One conjunct reads it: '0' marks a bare character, so /^0+$/ asks
precisely whether every character of the digit run was unquoted.

The regression arms come in both directions. The quoted rows (glued,
detached, single-quoted, and the partially-quoted 2"3" that a
some-character-unquoted test would get wrong) must be scoped; the existing
unquoted `--files 2>&1` row is the negative control and must stay unscoped,
so an implementation that simply stopped consuming IO numbers altogether
fails instead of passing.

No live instance exists in any of the six scan roots, so this is latent
rather than urgent — a false positive, never a silent miss.

Co-authored-by: Tom Boucher <trekkie@nomorestars.com>
This commit is contained in:
Michel Moreira
2026-09-07 12:47:43 -03:00
committed by GitHub
parent 476394689a
commit 93abf3a7b6
2 changed files with 30 additions and 1 deletions

View File

@@ -146,8 +146,17 @@ const tokenize = (str) => {
// Redirections: the operator and its target are consumed by the shell,
// not passed as arguments. A glued all-digit word is an IO number
// (`2>&1`) and belongs to the redirection, not to argv.
//
// #4276: POSIX recognizes an IO number only when the digit run is
// UNQUOTED, so the test has to read the quoting and not just the
// characters. `cur` has already lost that distinction — `"2"` and `2`
// reach here identically — and `curMask` is where it survives ('0' marks
// a bare character). Without the mask conjunct a correct
// `--files "2">out` had its value eaten as an IO number and scored as an
// unscoped invocation: a false positive on documentation that was right.
if (ch === '>' || ch === '<') {
if (started && /^[0-9]+$/.test(cur)) { cur = ''; curMask = ''; started = false; } else { flush(i); }
const bareDigitRun = /^[0-9]+$/.test(cur) && /^0+$/.test(curMask);
if (started && bareDigitRun) { cur = ''; curMask = ''; started = false; } else { flush(i); }
let j = i + 1;
if (str[j] === ch) j += 1; // >> / <<
if (str[j] === '&') j += 1; // >& (2>&1)