mirror of
https://github.com/neovim/neovim.git
synced 2026-05-24 05:40:08 +00:00
fix(eval): writestring() handling of null #39328
Problem: - write_blob, write_string dereference args which may be NULL. - `writefile(v:_null_blob, …)` fails. Solution: - Fix the annotation. - Handle null blob. Co-authored-by: zeertzjq <zeertzjq@outlook.com>
This commit is contained in:
@@ -65,6 +65,13 @@ describe('writefile()', function()
|
||||
eq('\n', read_file(fname))
|
||||
end)
|
||||
|
||||
it('writes a null blob to a file', function()
|
||||
eq(0, fn.writefile({ 'line1' }, fname, 'b'))
|
||||
eq('line1', read_file(fname))
|
||||
command(('call writefile(v:_null_blob, "%s")'):format(fname))
|
||||
eq('', read_file(fname))
|
||||
end)
|
||||
|
||||
it('appends to a file', function()
|
||||
eq(nil, read_file(fname))
|
||||
eq(0, fn.writefile({ 'abc', 'def', 'ghi' }, fname))
|
||||
@@ -100,7 +107,7 @@ describe('writefile()', function()
|
||||
eq('a\0', read_file(fname))
|
||||
end)
|
||||
|
||||
it('writes Lua strings to a file', function()
|
||||
it('writes Lua (binary) strings to a file', function()
|
||||
eq(0, exec_lua([[return vim.fn.writefile('foo\0bar', ..., 'b')]], fname))
|
||||
eq('foo\0bar', read_file(fname))
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user