From 6d0cdcd605cda4041f7d924e11eebe6039769bc1 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 26 Apr 2026 09:55:52 -0400 Subject: fix(eval): writestring() handling of null #39328 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- test/functional/vimscript/writefile_spec.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'test/functional/vimscript') diff --git a/test/functional/vimscript/writefile_spec.lua b/test/functional/vimscript/writefile_spec.lua index f406e5a469..b784868a7b 100644 --- a/test/functional/vimscript/writefile_spec.lua +++ b/test/functional/vimscript/writefile_spec.lua @@ -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) -- cgit