fix(system): don't treat NUL at start as no input (#34167)

This commit is contained in:
zeertzjq
2025-05-25 09:28:11 +08:00
parent 334d8f506f
commit cefc91a82e
2 changed files with 11 additions and 5 deletions

View File

@ -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_decide_throttle(0); // Initialize throttle decider.
out_data_ring(NULL, 0); // Initialize output ring-buffer. 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 // the output buffer
StringBuilder buf = KV_INITIAL_VALUE; StringBuilder buf = KV_INITIAL_VALUE;

View File

@ -374,8 +374,8 @@ describe('system()', function()
describe('with linefeed characters inside List items', function() describe('with linefeed characters inside List items', function()
it('converts linefeed characters to NULs', function() it('converts linefeed characters to NULs', function()
eq( eq(
'l1\001p2\nline2\001a\001b\nl3', '\001l1\001p2\nline2\001a\001b\nl3',
eval([[system('cat -', ["l1\np2", "line2\na\nb", 'l3'])]]) eval([[system('cat -', ["\nl1\np2", "line2\na\nb", 'l3'])]])
) )
end) end)
end) end)
@ -496,8 +496,8 @@ describe('systemlist()', function()
describe('with linefeed characters inside list items', function() describe('with linefeed characters inside list items', function()
it('converts linefeed characters to NULs', function() it('converts linefeed characters to NULs', function()
eq( eq(
{ 'l1\np2', 'line2\na\nb', 'l3' }, { '\nl1\np2', 'line2\na\nb', 'l3' },
eval([[systemlist('cat -', ["l1\np2", "line2\na\nb", 'l3'])]]) eval([[systemlist('cat -', ["\nl1\np2", "line2\na\nb", 'l3'])]])
) )
end) end)
end) end)
@ -558,6 +558,12 @@ end)
describe('shell :!', function() describe('shell :!', function()
before_each(clear) 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() it(':{range}! with powershell filter/redirect #16271 #19250', function()
local screen = Screen.new(500, 8) local screen = Screen.new(500, 8)
local found = n.set_shell_powershell(true) local found = n.set_shell_powershell(true)