Repository navigation
fix(tools): open a path with a line break as one file in openFile and openDiff - #608
Conversation
openFile and openDiff open a file with vim.cmd("edit " .. fnameescape(path)).
fnameescape() keeps a line break in the name, and vim.cmd() with a string runs
each line as its own Ex command, so the text after the line break runs.
The real-Neovim spec plants a file whose name holds a line break followed by
a command that sets g:claudecode_injected, and opens it through openFile,
diff.open_diff_blocking and the legacy diff.open_diff (as the original and as
the new file the temp file is named after). It fails on Neovim 0.8.0, 0.11.6
and 0.12.3: the command runs.
The unit specs expect openFile and openDiff to refuse a path that holds a
line feed, a carriage return or a NUL with -32602, naming the parameter,
before anything reads the path. They fail: both handlers accept such a path.
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
The module calls filereadable for the loaded buffers when it loads, so the spec cannot expect no call at all. It expects no call with the refused path. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
openFile and openDiff opened files with vim.cmd("edit " .. fnameescape(path)).
fnameescape() puts a backslash before a line break but keeps it, and vim.cmd()
with a string runs each line as its own Ex command, so a filePath,
old_file_path or new_file_path with a line break ran the text after it (Lua
and shell through :lua and :!). The legacy diff.open_diff names its temp file
after new_file_path, so that path alone was enough there.
The four sinks now use vim.cmd.edit(), which runs one command through
nvim_cmd and never splits it. They keep fnameescape(): without it, nvim_cmd
runs a relative name that starts with + as a +cmd. The temp file keeps
:noswapfile through mods.
openFile and openDiff also refuse a path that holds a line feed, a carriage
return or a NUL with -32602, naming the parameter, before anything reads it.
filereadable() raises E976 on a NUL.
The mock vim.cmd is now callable and indexable (tests/helpers/ex_command.lua),
and records vim.cmd.edit(x) as "edit x", as the string form did. The specs
that replace vim.cmd and reach a changed sink use the same helper.
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
|
@codex review |
|
@codex security review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
PASS+NOTES Verified head faa378a against parent 6ad8e0f. Each check ran on Neovim 0.12.3 and 0.8.0 (official release tarball). A headless nvim loaded the tree under test (
Evidence (parent 0.12.3, openFile): Notes:
Generated with |
Why
A file whose name holds a line break ran the text after the break as an Ex command in the user's Neovim. That text can be
:luaor:!, so a contributor who commits such a file gets code execution when Claude opens it withopenFileor proposes an edit withopenDiff.fnameescape()puts a backslash before the line break but keeps the byte, andvim.cmd("edit " .. path)runs its string as a script, one command per line.What changed
vim.cmd.edit(vim.fn.fnameescape(path)):open_fromintools/open_file.lua, andload_original_bufferandshow_native_diff(original and temp file) indiff.lua. The temp file of the legacydiff.open_diffis named afternew_file_path, so that path alone was enough there.openFileandopenDiffrefuse afilePath,old_file_pathornew_file_paththat holds\n,\ror NUL with-32602, naming the parameter, before anything reads the path.filereadable()raises E976 on a NUL.vim.cmdis callable and indexable (tests/helpers/ex_command.lua) and recordsvim.cmd.edit(x)asedit x. Three specs that replacedvim.cmdwithout restoring it now use the helper.tools/README.mdlists the new refusals.ARCHITECTURE.mdno longer showsvim.cmd("edit " .. params.filePath).covered.lockis re-recorded (hash lines only).Tradeoffs
fnameescapestays.vim.cmd.edit({ args = { path }, magic = { file = false } })without it ran a relative name+lua(...)as a+cmdon Neovim 0.12.3.bufadd()withnvim_win_set_buf()would skip the Ex parser, but also E37 under'nohidden', the jumplist, the alternate file and leaving Visual mode, which:editgives.Blast radius
Paths without a line break or NUL open as before: 24 names with space,
$,%,#,[,{, leading+,++ff=dos, backtick,|, quotes, tab and CR gave the same buffer name and text with both forms on 0.8.0, 0.11.6 and 0.12.3. A file whose name holds a line break now opens literally through the diff, andopenFile/openDiffrefuse it.Verification
tests/integration/file_name_line_break_spec.lua(real Neovim): 0/4 pass on the test commits, 4/4 with the fix, on 0.8.0, 0.11.6 and 0.12.3. 9 new unit tests for the refusals fail before the fix.README\nlua(load(string.char(...)))(): before,openFileandopenDiffwrote the output ofidto a file on 0.8.0 and 0.12.3. After, both answer-32602and nothing runs. All fouropenDifflayouts (vertical/horizontal, with and without a new tab) open a diff and run nothing.mise run all: 0 warnings, 2034 successes, 0 failures (seed 1795453244).verify-diff-lifecycle/check.sh: PASS.Generated with
xum• Model:anthropic:claude-opus-5-5• Thinking:high