From cefc91a82e26df3c8392a499f8f49c23516eb32b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 25 May 2025 09:28:11 +0800 Subject: [PATCH] fix(system): don't treat NUL at start as no input (#34167) --- src/nvim/os/shell.c | 2 +- test/functional/vimscript/system_spec.lua | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index e711611d67..5bfec83442 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -856,7 +856,7 @@ static int do_os_system(char **argv, const char *input, size_t len, char **outpu { out_data_decide_throttle(0); // Initialize throttle decider. out_data_ring(NULL, 0); // Initialize output ring-buffer. - bool has_input = (input != NULL && input[0] != NUL); + bool has_input = (input != NULL && len > 0); // the output buffer StringBuilder buf = KV_INITIAL_VALUE; diff --git a/test/functional/vimscript/system_spec.lua b/test/functional/vimscript/system_spec.lua index 2813128aae..5b464b3dad 100644 --- a/test/functional/vimscript/system_spec.lua +++ b/test/functional/vimscript/system_spec.lua @@ -374,8 +374,8 @@ describe('system()', function() describe('with linefeed characters inside List items', function() it('converts linefeed characters to NULs', function() eq( - 'l1\001p2\nline2\001a\001b\nl3', - eval([[system('cat -', ["l1\np2", "line2\na\nb", 'l3'])]]) + '\001l1\001p2\nline2\001a\001b\nl3', + eval([[system('cat -', ["\nl1\np2", "line2\na\nb", 'l3'])]]) ) end) end) @@ -496,8 +496,8 @@ describe('systemlist()', function() describe('with linefeed characters inside list items', function() it('converts linefeed characters to NULs', function() eq( - { 'l1\np2', 'line2\na\nb', 'l3' }, - eval([[systemlist('cat -', ["l1\np2", "line2\na\nb", 'l3'])]]) + { '\nl1\np2', 'line2\na\nb', 'l3' }, + eval([[systemlist('cat -', ["\nl1\np2", "line2\na\nb", 'l3'])]]) ) end) end) @@ -558,6 +558,12 @@ end) describe('shell :!', function() before_each(clear) + it(':{range}! works when the first char is NUL #34163', function() + api.nvim_buf_set_lines(0, 0, -1, true, { '\0hello', 'hello' }) + command('%!cat') + eq({ '\0hello', 'hello' }, api.nvim_buf_get_lines(0, 0, -1, true)) + end) + it(':{range}! with powershell filter/redirect #16271 #19250', function() local screen = Screen.new(500, 8) local found = n.set_shell_powershell(true)