fix(cmd): ++p, ++edit should match "word" boundary #39146

Problem: `:write ++patate foo` doesn't error out, instead it turns on
mkdir_p and uses "atate foo" as the filename. Same with ++edit.
The parser just does strncmp without checking what comes after.

Solution: require the next char after the option name to not be a
letter

(cherry picked from commit 44770bb924)
This commit is contained in:
glepnir
2026-04-22 16:43:07 +08:00
committed by github-actions[bot]
parent 15d824e5d6
commit ba3de79ccb
2 changed files with 11 additions and 2 deletions

View File

@@ -124,6 +124,10 @@ describe(':write', function()
eq(1, eval("filereadable('Xtest_write/write2/p_opt.txt')"))
eq(1, eval("filereadable('Xtest_write/write2/p_opt2.txt')"))
eq(0, eval("filereadable('Xtest_write/write3/p_opt3.txt')"))
t.matches(
'E474: Invalid argument',
pcall_err(command, 'read ++edits Xtest_write/write/p_opt.txt')
)
eq('Vim(write):E32: No file name', pcall_err(command, 'write ++p Xotherdir/'))
if not is_os('win') then
@@ -136,6 +140,11 @@ describe(':write', function()
pcall_err(command, 'write ++p ./')
)
end
t.matches(
'E474: Invalid argument',
pcall_err(command, 'write ++patate Xtest_write/garbage.txt')
)
end)
it('errors out correctly', function()