From a1ddc722e797b8315a56ea2ab66043da294364af Mon Sep 17 00:00:00 2001 From: generaltony007 <191973953+hakarrr@users.noreply.github.com> Date: Tue, 17 Nov 2026 20:54:41 +0530 Subject: [PATCH] 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> --- bin/main.js | 4 ++++ man/marked.1.md | 3 +++ test/unit/bin.test.js | 23 +++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/bin/main.js b/bin/main.js index 2db87950..2174f139 100644 --- a/bin/main.js +++ b/bin/main.js @@ -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': diff --git a/man/marked.1.md b/man/marked.1.md index a4b360d8..b47ad196 100644 --- a/man/marked.1.md +++ b/man/marked.1.md @@ -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. diff --git a/test/unit/bin.test.js b/test/unit/bin.test.js index befaefc7..e5e325db 100644 --- a/test/unit/bin.test.js +++ b/test/unit/bin.test.js @@ -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: '

test

', + })); + + 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, '

~~file contents~~

\n\n'); + assert.strictEqual(stderr, ''); + } finally { + await rm(dir, { recursive: true, force: true }); + } + }); + } + it('input file positional', testInput({ args: [fixturePath('bin-input.md')], stdout: '

file

',