fix(arg-parser): a quoted value stops at a quote that starts a word and never swallows a later flag

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-10-28 15:18:55 +01:00
commit 8be0c05221
Signed by: ktg
SSH key fingerprint: SHA256:JakMjO6FTBBzN0Bhfj9saOoEjaFxlSdYuZQQpM/lF9Q
2 changed files with 32 additions and 6 deletions

View file

@ -0,0 +1,19 @@
import { test } from 'node:test';
import { strict as assert } from 'node:assert';
import { parseArgs, tokenize } from '../../lib/parsers/arg-parser.mjs';
const values = (text) => tokenize(text).map((t) => t.value);
test('[TOK] a quoted value never swallows a later flag, and an apostrophe inside a word keeps its value', () => {
const text = '--project "my dir"/x --since "HEAD~1"';
assert.equal(parseArgs(text, 'trekreview').flags['--since'], 'HEAD~1',
'the quote after `dir` is followed by `/`, so it does not close; the search stops at the quote that starts `"HEAD~1"`');
assert.deepEqual(values(text), ['--project', '"my', 'dir"/x', '--since', 'HEAD~1']);
// Control: an apostrophe inside a word in single quotes keeps one value.
assert.deepEqual(values(`'Fix the user's login'`), ["Fix the user's login"]);
// Control: two adjacent quoted words stay two values.
assert.deepEqual(values(`"a" "b"`), ['a', 'b']);
// Control: the other kind of quote inside a quoted value does not split it.
assert.deepEqual(values(`"say 'hi' now"`), ["say 'hi' now"]);
});