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:
parent
52c382c198
commit
8be0c05221
2 changed files with 32 additions and 6 deletions
19
tests/lib/arg-parser-tokenize.test.mjs
Normal file
19
tests/lib/arg-parser-tokenize.test.mjs
Normal 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"]);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue