diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 525475b60b..e9e2516d58 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -5168,8 +5168,9 @@ A jump table for the options with a short description can be found at |Q_op|. Note that such processing is done after |:set| did its own round of unescaping, so to keep yourself sane use |:let-&| like shown above. *shell-powershell* - To use powershell (on Windows): > - set shell=powershell shellquote=( shellpipe=\| shellxquote= + To use powershell: > + let &shell = has('win32') ? 'powershell' : 'pwsh' + set shellquote= shellpipe=\| shellxquote= set shellcmdflag=-NoLogo\ -NoProfile\ -ExecutionPolicy\ RemoteSigned\ -Command set shellredir=\|\ Out-File\ -Encoding\ UTF8 diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 4b4b2c416f..05e3d90c8f 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -2692,8 +2692,8 @@ win_line ( off += col; } - // wont highlight after 1024 columns - int term_attrs[1024] = {0}; + // wont highlight after TERM_ATTRS_MAX columns + int term_attrs[TERM_ATTRS_MAX] = { 0 }; if (wp->w_buffer->terminal) { terminal_get_line_attributes(wp->w_buffer->terminal, wp, lnum, term_attrs); extra_check = true; @@ -4030,7 +4030,7 @@ win_line ( int n = wp->w_p_rl ? -1 : 1; while (col >= 0 && col < grid->Columns) { schar_from_ascii(linebuf_char[off], ' '); - linebuf_attr[off] = term_attrs[vcol]; + linebuf_attr[off] = vcol >= TERM_ATTRS_MAX ? 0 : term_attrs[vcol]; off += n; vcol += n; col += n; diff --git a/src/nvim/screen.h b/src/nvim/screen.h index 61ed98247d..754ab06bec 100644 --- a/src/nvim/screen.h +++ b/src/nvim/screen.h @@ -32,6 +32,9 @@ EXTERN ScreenGrid default_grid INIT(= SCREEN_GRID_INIT); #define DEFAULT_GRID_HANDLE 1 // handle for the default_grid +// Maximum columns for terminal highlight attributes +#define TERM_ATTRS_MAX 1024 + /// Status line click definition typedef struct { enum { diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 7609006906..3de6f19cda 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -588,6 +588,7 @@ void terminal_get_line_attributes(Terminal *term, win_T *wp, int linenr, return; } + width = MIN(TERM_ATTRS_MAX, width); for (int col = 0; col < width; col++) { VTermScreenCell cell; bool color_valid = fetch_cell(term, row, col, &cell); diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index bd36bac062..dbaedd6f60 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -500,9 +500,20 @@ function module.source(code) end function module.set_shell_powershell() + local shell = iswin() and 'powershell' or 'pwsh' + if not module.eval('executable("'..shell..'")') then + error(shell..' is not executable') + end + local aliases = iswin() and {'cat', 'sleep'} or {} + local cmd = '' + for _, alias in ipairs(aliases) do + cmd = cmd .. 'Remove-Item -Force alias:' .. alias .. ';' + end module.source([[ - set shell=powershell shellquote=( shellpipe=\| shellredir=> shellxquote= - let &shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command Remove-Item -Force alias:sleep; Remove-Item -Force alias:cat;' + let &shell = ']]..shell..[[' + set shellquote= shellpipe=\| shellxquote= + let &shellredir = '| Out-File -Encoding UTF8' + let &shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command ]]..cmd..[[' ]]) end diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index c6ea0c0e6b..fb6e0d0e94 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -264,3 +264,12 @@ describe('No heap-buffer-overflow when using', function() feed_command('bdelete!') end) end) + +describe('No heap-buffer-overflow when', function() + it('set nowrap and send long line #11548', function() + feed_command('set nowrap') + feed_command('autocmd TermOpen * startinsert') + feed_command('call feedkeys("4000ai\\:terminal!\\")') + eq(2, eval('1+1')) + end) +end) diff --git a/test/functional/ui/output_spec.lua b/test/functional/ui/output_spec.lua index c028f44b44..c5d3e536ad 100644 --- a/test/functional/ui/output_spec.lua +++ b/test/functional/ui/output_spec.lua @@ -10,6 +10,7 @@ local iswin = helpers.iswin local clear = helpers.clear local command = helpers.command local nvim_dir = helpers.nvim_dir +local set_shell_powershell = helpers.set_shell_powershell describe("shell command :!", function() local screen @@ -230,4 +231,19 @@ describe("shell command :!", function() ]]) end) end) + if iswin() or eval('executable("pwsh")') == 1 then + it('powershell supports literal strings', function() + set_shell_powershell() + local screen = Screen.new(30, 4) + screen:attach() + feed_command([[!'echo $a']]) + screen:expect{any='\necho %$a', timeout=10000} + feed_command([[!$a = 1; echo '$a']]) + screen:expect{any='\n%$a', timeout=10000} + feed_command([[!"echo $a"]]) + screen:expect{any='\necho', timeout=10000} + feed_command([[!$a = 1; echo "$a"]]) + screen:expect{any='\n1', timeout=10000} + end) + end end) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 4cd18efcf3..a31bd88189 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -160,8 +160,8 @@ set(UNIBILIUM_SHA256 29815283c654277ef77a3adcc8840db79ddbb20a0f0b0c8f648bd8cd49a set(LIBTERMKEY_URL http://www.leonerd.org.uk/code/libtermkey/libtermkey-0.21.1.tar.gz) set(LIBTERMKEY_SHA256 cecbf737f35d18f433c8d7864f63c0f878af41f8bd0255a3ebb16010dc044d5f) -set(LIBVTERM_URL https://github.com/neovim/libvterm/archive/7c72294d84ce20da4c27362dbd7fa4b08cfc91da.tar.gz) -set(LIBVTERM_SHA256 f30c4d43e0c6db3e0912daf7188d98fbf6ee88f97589d72f6f304e5db48826a8) +set(LIBVTERM_URL http://www.leonerd.org.uk/code/libvterm/libvterm-0.1.4.tar.gz) +set(LIBVTERM_SHA256 bc70349e95559c667672fc8c55b9527d9db9ada0fb80a3beda533418d782d3dd) set(LUV_VERSION 1.30.0-0) set(LUV_URL https://github.com/luvit/luv/archive/${LUV_VERSION}.tar.gz) diff --git a/third-party/cmake/BuildLibvterm.cmake b/third-party/cmake/BuildLibvterm.cmake index 61c1c90fa6..c3485dac25 100644 --- a/third-party/cmake/BuildLibvterm.cmake +++ b/third-party/cmake/BuildLibvterm.cmake @@ -27,7 +27,6 @@ function(BuildLibvterm) -DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake PATCH_COMMAND "${_libvterm_PATCH_COMMAND}" - CONFIGURE_COMMAND "" BUILD_IN_SOURCE 1 CONFIGURE_COMMAND "${_libvterm_CONFIGURE_COMMAND}" BUILD_COMMAND "${_libvterm_BUILD_COMMAND}"