Skip to content

🏗️🔧:stop a filename being read as an option - #903

Open
DerekNonGeneric wants to merge 1 commit into
mainfrom
infra/quote-option-lookalikes
Open

🏗️🔧:stop a filename being read as an option#903
DerekNonGeneric wants to merge 1 commit into
mainfrom
infra/quote-option-lookalikes

Conversation

@DerekNonGeneric

@DerekNonGeneric DerekNonGeneric commented Sep 5, 2026

Copy link
Copy Markdown
Member

Follow-on from #888, found while sweeping the portal for the same class
of bug after a review there. Quoting a filename settles what the shell
does with it and nothing about what the tool then makes of it.

quote('--write.md') produces '--write.md'. The shell strips the
quotes and prettier receives --write.md, which it reads as an option:

$ prettier --check '--write.md' 'ok.md'
[error] Cannot read properties of null (reading 'md')
$ echo $?
0

Exit 0. A check that passed having checked nothing, which is worse
than one that failed — verify.md would go green while quietly
processing neither file.

The fix

A leading ./ says the argument is a path. Two characters, and only on
the names that need them; an ordinary or absolute path is untouched.

Demonstrated end to end

A file called --write.md holding deliberately bad Markdown:

result
before [error] Cannot read properties of null, task exits 0
after [warn] --write.md from prettier, and MD019/no-multiple-space-atx from markdownlint

So the file is genuinely checked rather than silently skipped.

Why it is worth doing at all

verify.filenames would reject such a name — but as #900 explains, it is
one task among the rest and a failing one does not stop the others being
handed what it just objected to. A filename is input chosen by whoever
opens the pull request, and it turned out to have two ways of mattering
rather than one.

The portal needs the same change; I will fold it into
openinf.github.io#1881,
which is where its copy of quote() lives.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of file paths beginning with -, ensuring command-line tools interpret them as paths rather than options.
    • Preserved existing behavior for ordinary relative and absolute paths.
  • Tests

    • Added coverage for option-like filenames, including --write.md and -.

Quoting settles what the shell does with a name and nothing about what
the tool then makes of it. `'--write.md'` reaches prettier as
`--write.md`, and prettier reads it as an option: it printed
`Cannot read properties of null` and exited 0. A check that passed
having checked nothing, which is worse than one that failed.

A leading `./` says the argument is a path. It costs a relative name two
characters and only the names that need it get them.

Demonstrated on a file called `--write.md` holding deliberately bad
Markdown. Before: prettier errored and the task exited 0. After:
prettier reports the file, and markdownlint reports MD019 inside it.

This is the residue of the same defect as the quoting itself -- a
filename is attacker-chosen input that reaches a command line, and there
were two ways for it to matter rather than one.

Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
Assisted-by: Claude-Code:claude-opus-5
@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 3f6f151e-4ff0-429f-a810-ea87095950b8

📥 Commits

Reviewing files that changed from the base of the PR and between 90f87d8 and cc07c50.

📒 Files selected for processing (2)
  • build/utils.mts
  • build/utils.test.mts

Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

The quote function now prefixes paths that begin with - with ./ before shell escaping. Tests cover option-like filenames and confirm unchanged behavior for ordinary relative and absolute paths.

Changes

Shell Path Quoting

Layer / File(s) Summary
Quote normalization and validation
build/utils.mts, build/utils.test.mts
quote prefixes dash-prefixed paths with ./ before applying shell escaping. Tests cover option-like, relative, and absolute paths.

Estimated code review effort: 2 (Simple) | ~5 minutes

Merge Risk: ⚪ Minimal · up to cc07c

Dash-prefixed relative filenames are now passed as paths rather than options, while normal and absolute paths retain their existing behavior. The change is covered and ready to merge.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: preventing filenames from being interpreted as command-line options. The emojis add noise but do not obscure the meaning.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch infra/quote-option-lookalikes

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant