fix: honor the CLI end-of-options marker (#4230)

* fix: honor the CLI end-of-options marker

Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>

* test: cover hyphen-prefixed input files after --

Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>

* docs: document the CLI option terminator

Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>

---------

Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
This commit is contained in:
generaltony007
2026-11-17 08:24:41 -07:00
committed by GitHub
co-authored by GeneralTony007
parent c6b22e89ba
commit a1ddc722e7
3 changed files with 30 additions and 0 deletions
+4
View File
@@ -98,6 +98,10 @@ export async function main(nodeProcess) {
}
while (argv.length) {
if (argv[0] === '--') {
files.push(...argv.slice(1));
break;
}
arg = getArg();
switch (arg) {
case '-o':
+3
View File
@@ -29,6 +29,9 @@ marked --output="hello world.html" -i in.md --no-breaks
## OPTIONS
* --
End option parsing. Arguments after this are treated as input filenames, even if they start with a hyphen.
* -o, --output [output file]
Specify file output. If none is specified, write to stdout.
+23
View File
@@ -304,6 +304,29 @@ describe('bin/marked', () => {
});
describe('input', () => {
it('does not treat --=value as the end of options', testInput({
args: ['--=ignored', '--string', '# test'],
stdout: '<h1>test</h1>',
}));
for (const filename of ['-s.md', '--version']) {
it(`treats ${filename} as a filename after --`, async() => {
const dir = await mkdtemp(resolve(tmpdir(), 'marked-end-options-'));
try {
await writeFile(resolve(dir, filename), '~~file contents~~');
const { stdout, stderr } = await execFileAsync(process.execPath, [
resolve(import.meta.dirname, '../../bin/marked.js'),
'--no-gfm', '--', filename,
], { cwd: dir });
assert.strictEqual(stdout, '<p>~~file contents~~</p>\n\n');
assert.strictEqual(stderr, '');
} finally {
await rm(dir, { recursive: true, force: true });
}
});
}
it('input file positional', testInput({
args: [fixturePath('bin-input.md')],
stdout: '<h1>file</h1>',