feat(eval): treat Lua string as "blob" in writefile() #39098

Problem:
vim.fn.writefile() treats Lua strings as Vimscript strings instead of a "binary clean" string.

Solution:
Treat Lua-originated strings as blob data.
This commit is contained in:
Barrett Ruth
2026-04-22 13:36:43 -04:00
committed by GitHub
parent 496374e951
commit fb6aeaba2d
3 changed files with 27 additions and 4 deletions

View File

@@ -6,6 +6,7 @@ local clear = n.clear
local eq = t.eq
local fn = n.fn
local api = n.api
local exec_lua = n.exec_lua
local read_file = t.read_file
local write_file = t.write_file
local pcall_err = t.pcall_err
@@ -99,6 +100,11 @@ describe('writefile()', function()
eq('a\0', read_file(fname))
end)
it('writes Lua strings to a file', function()
eq(0, exec_lua([[return vim.fn.writefile('foo\0bar', ..., 'b')]], fname))
eq('foo\0bar', read_file(fname))
end)
it('shows correct file name when supplied numbers', function()
api.nvim_set_current_dir(dname)
eq(