mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	fix(api): handle NUL in nvim_err_write() and nvim_out_write()
(cherry picked from commit 49254ddebe)
			
			
This commit is contained in:
		 zeertzjq
					zeertzjq
				
			
				
					committed by
					
						![github-actions[bot]](/assets/img/avatar_default.png) github-actions[bot]
						github-actions[bot]
					
				
			
			
				
	
			
			
			![github-actions[bot]](/assets/img/avatar_default.png) github-actions[bot]
						github-actions[bot]
					
				
			
						parent
						
							c21ca9b87a
						
					
				
				
					commit
					00c3ffdb4b
				
			| @@ -1692,6 +1692,8 @@ static void write_msg(String message, bool to_err, bool writeln) | |||||||
|     msg_didout = true; \ |     msg_didout = true; \ | ||||||
|     kv_drop(line_buf, kv_size(line_buf)); \ |     kv_drop(line_buf, kv_size(line_buf)); \ | ||||||
|     kv_resize(line_buf, LINE_BUFFER_MIN_SIZE); \ |     kv_resize(line_buf, LINE_BUFFER_MIN_SIZE); \ | ||||||
|  |   } else if (c == NUL) { \ | ||||||
|  |     kv_push(line_buf, NL); \ | ||||||
|   } else { \ |   } else { \ | ||||||
|     kv_push(line_buf, c); \ |     kv_push(line_buf, c); \ | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -1994,6 +1994,19 @@ describe('API', function() | |||||||
|   end) |   end) | ||||||
|  |  | ||||||
|   describe('nvim_out_write', function() |   describe('nvim_out_write', function() | ||||||
|  |     local screen | ||||||
|  |  | ||||||
|  |     before_each(function() | ||||||
|  |       screen = Screen.new(40, 8) | ||||||
|  |       screen:attach() | ||||||
|  |       screen:set_default_attr_ids({ | ||||||
|  |         [0] = {bold = true, foreground = Screen.colors.Blue}, | ||||||
|  |         [1] = {bold = true, foreground = Screen.colors.SeaGreen}, | ||||||
|  |         [2] = {bold = true, reverse = true}, | ||||||
|  |         [3] = {foreground = Screen.colors.Blue}, | ||||||
|  |       }) | ||||||
|  |     end) | ||||||
|  |  | ||||||
|     it('prints long messages correctly #20534', function() |     it('prints long messages correctly #20534', function() | ||||||
|       exec([[ |       exec([[ | ||||||
|         set more |         set more | ||||||
| @@ -2014,14 +2027,7 @@ describe('API', function() | |||||||
|       eq('\naaa\n' .. ('a'):rep(5002) .. '\naaa', meths.get_var('out')) |       eq('\naaa\n' .. ('a'):rep(5002) .. '\naaa', meths.get_var('out')) | ||||||
|     end) |     end) | ||||||
|  |  | ||||||
|     it('blank line in message works', function() |     it('blank line in message', function() | ||||||
|       local screen = Screen.new(40, 8) |  | ||||||
|       screen:attach() |  | ||||||
|       screen:set_default_attr_ids({ |  | ||||||
|         [0] = {bold = true, foreground = Screen.colors.Blue}, |  | ||||||
|         [1] = {bold = true, foreground = Screen.colors.SeaGreen}, |  | ||||||
|         [2] = {bold = true, reverse = true}, |  | ||||||
|       }) |  | ||||||
|       feed([[:call nvim_out_write("\na\n")<CR>]]) |       feed([[:call nvim_out_write("\na\n")<CR>]]) | ||||||
|       screen:expect{grid=[[ |       screen:expect{grid=[[ | ||||||
|                                                 | |                                                 | | ||||||
| @@ -2046,6 +2052,20 @@ describe('API', function() | |||||||
|         {1:Press ENTER or type command to continue}^ | |         {1:Press ENTER or type command to continue}^ | | ||||||
|       ]]} |       ]]} | ||||||
|     end) |     end) | ||||||
|  |  | ||||||
|  |     it('NUL bytes in message', function() | ||||||
|  |       feed([[:lua vim.api.nvim_out_write('aaa\0bbb\0\0ccc\nddd\0\0\0eee\n')<CR>]]) | ||||||
|  |       screen:expect{grid=[[ | ||||||
|  |                                                 | | ||||||
|  |         {0:~                                       }| | ||||||
|  |         {0:~                                       }| | ||||||
|  |         {0:~                                       }| | ||||||
|  |         {2:                                        }| | ||||||
|  |         aaa{3:^@}bbb{3:^@^@}ccc                         | | ||||||
|  |         ddd{3:^@^@^@}eee                            | | ||||||
|  |         {1:Press ENTER or type command to continue}^ | | ||||||
|  |       ]]} | ||||||
|  |     end) | ||||||
|   end) |   end) | ||||||
|  |  | ||||||
|   describe('nvim_err_write', function() |   describe('nvim_err_write', function() | ||||||
| @@ -2134,6 +2154,20 @@ describe('API', function() | |||||||
|       ]]) |       ]]) | ||||||
|       feed('<cr>')  -- exit the press ENTER screen |       feed('<cr>')  -- exit the press ENTER screen | ||||||
|     end) |     end) | ||||||
|  |  | ||||||
|  |     it('NUL bytes in message', function() | ||||||
|  |       nvim_async('err_write', 'aaa\0bbb\0\0ccc\nddd\0\0\0eee\n') | ||||||
|  |       screen:expect{grid=[[ | ||||||
|  |                                                 | | ||||||
|  |         {0:~                                       }| | ||||||
|  |         {0:~                                       }| | ||||||
|  |         {0:~                                       }| | ||||||
|  |         {3:                                        }| | ||||||
|  |         {1:aaa^@bbb^@^@ccc}                         | | ||||||
|  |         {1:ddd^@^@^@eee}                            | | ||||||
|  |         {2:Press ENTER or type command to continue}^ | | ||||||
|  |       ]]} | ||||||
|  |     end) | ||||||
|   end) |   end) | ||||||
|  |  | ||||||
|   describe('nvim_err_writeln', function() |   describe('nvim_err_writeln', function() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user