Commit Graph

6995 Commits

Author SHA1 Message Date
Justin M. Keyes
cf6660d3c1 backport: fix(mpack): boundary values for negative integer encoding (#38411)
fix(mpack): boundary values for negative integer encoding

Problem:
libmpack encodes boundary values -129 and -32769 with wrong integer
sizes:
- -129 as int8 instead of int16
- -32769 as int16 instead of int32
because the boundary checks compare against the wrong values (e.g., lo
< 0xffffff7f instead of lo < 0xffffff80). This caused data corruption:
-129 would decode as 127.

Solution:
Fix off-by-one errors in the two's complement boundary constants:
0xffffff80 (-128, min int8) and 0xffff8000 (-32768, min int16).

Co-authored-by: benarcher2691 <ben.archer2691@gmail.com>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-21 21:30:02 -04:00
zeertzjq
8189bb8e48 test: include :cd in pcall() in rmdir() (#38278)
If the Nvim session has exited, the nvim_command will fail too.

ERROR    test/functional/core/fileio_spec.lua @ 342: tmpdir failure modes
test\functional\testnvim.lua:133: sending request after EOF from Nvim

stack traceback:
	test\functional\testnvim.lua:133: in function 'command'
	test\functional\testnvim.lua:847: in function 'rmdir'
	test/functional/core\fileio_spec.lua:353: in function <test/functional/core\fileio_spec.lua:342>

(cherry picked from commit b027de3a87)
2026-03-13 00:25:33 +00:00
glepnir
9b13ee041f fix(api): nvim_set_hl crashes when url= key is passed
Problem: Calling nvim_set_hl() with url= crashes because it tries to
free arena-owned string memory.

Solution: Remove the bad free and return a validation error instead.
(cherry picked from commit d19dc6339d)
2026-03-06 11:43:01 +00:00
Stefan VanBuren
85d4822797 fix(treesitter): normalize language aliases
Hyphenated language names are silently dropped when used as injections
(see #38132).

This combines the normalization of language aliases into `resolve_lang`,
and also adds the normalization of hyphens to underscores, which allows
for handling of injected language tags with hyphens in their names.

Fixes #38132.

(cherry picked from commit 01817eb6f3)
2026-03-04 18:30:41 +00:00
zeertzjq
f7af59d29b test(win_scrolled_resized_spec): fix flaky test (#37942)
(cherry picked from commit d23f28cca2)
2026-02-18 14:46:10 +00:00
zeertzjq
437f2e5a57 test(screen): fix minimal timeout too small for "intermediate" (#37933)
After #27620 flags.timeout is no longer used as the minimal timeout for
"intermediate", but the default minimal timeout shouldn't be too small.

(cherry picked from commit d0c699ec7b)
2026-02-18 12:18:09 +00:00
zeertzjq
f6bc9efe62 test: fix test failure causing following tests to fail (#37932)
(cherry picked from commit a520d9c4ea)
2026-02-18 10:17:38 +00:00
zeertzjq
b072f89d1e vim-patch:9.2.0004: Changing hidden prompt buffer cancels :startinsert/:stopinsert (#37881)
Problem:  Changing hidden prompt buffer cancels :startinsert/:stopinsert
          (after 9.0.1439).
Solution: Don't change mode for a prompt buffer in an autocommand
          window (zeertzjq).

closes: vim/vim#19410

8b81a6b6e1
(cherry picked from commit 7d8653575f)
2026-02-15 23:29:26 +00:00
zeertzjq
7bb3c3068c fix(highlight): setting 'winhl' doesn't work with global ns (#37868)
Problem:  Setting 'winhighlight' doesn't after setting global namespace
          using nvim_win_set_hl_ns().
Solution: Check if using another namespace when setting 'winhighlight'
          instead of disabling 'winhighlight' in nvim_win_set_hl_ns().
(cherry picked from commit f8d59cfab9)
2026-02-15 00:56:10 +00:00
glepnir
5c7a93917a test: move deprecated highlight API tests #37801
Problem: Tests for deprecated highlight API were mixed with current API tests.

Solution: Move them to deprecated_spec.lua and update highlight_spec.lua to use nvim_get_hl.
(cherry picked from commit 31c45f1aa4)
2026-02-15 00:30:10 +00:00
zeertzjq
7281cf883e fix(channel): possible hang after connecting with TCP times out (#37813)
Problem:  Possible hang after connecting with TCP times out.
Solution: Wait for the close callback to arrive.
2026-02-11 03:15:26 +00:00
zeertzjq
3a94763124 fix(channel): crash on failed sockconnect() (#37811)
Problem:  Crash on failed sockconnect() if a new connection is accepted
          while polling for uv events.
Solution: Don't use channel_destroy_early().

Also test "tcp" mode failure properly.

(cherry picked from commit 64ce5382bd)
2026-02-11 03:15:26 +00:00
zeertzjq
8fc81bc9e9 test: wait for uv.pipe_connect() callback (#37640)
Problem:
On Windows, writing to a pipe doesn't work if the pipe isn't connected
yet. This causes an RPC request to a session newly created by connect()
to hang, as it's waiting for a response to a request that never reaches
the server.

Solution:
Wait for uv.pipe_connect() callback to be called when using connect().
2026-02-11 03:15:26 +00:00
Sean Dewar
ddd7494ff9 test(terminal): skip flaky test on Windows (#37774)
Ref: https://github.com/neovim/neovim/pull/37758#discussion_r2778065203
(cherry picked from commit c90593ed5f)
2026-02-08 02:59:41 +00:00
zeertzjq
154f1c5abd test(api/server_requests_spec): fix flaky test (#37771)
Sometimes the scheduled :qall can arrive too late, so that EOF isn't
received in the same uv_run() call as the response.

(cherry picked from commit a9454f8511)
2026-02-08 01:18:45 +00:00
horrifyingHorse
37738d5ae0 fix(terminal): reset w_leftcol after resizing terminal
Problem: windows may scroll horizontally upon resize using the old terminal
size, which may be unnecessary and cause the content to be partially out-of-view.

Solution: reset the horizontal scroll after resizing.

Adjust expected highlights, as commit e946951f6a isn't backported.

(cherry picked from commit ba6440c106)
2026-02-06 16:37:43 +00:00
zeertzjq
818b97173e fix(process): avoid buffering unnecessary UI event with PTY CWD (#37582)
Problem:
Calling os_chdir() to change the child processes' CWD may cause some
unnecessary UI events to be buffered. These UI events don't go anywhere
as execvp() is called before flushing the UI buffer.

Solution:
Use uv_chdir() instead of os_chdir(). Also fix getting error string
incorrectly. Add test for the current behavior.

(cherry picked from commit 6291256868)
2026-02-06 01:30:33 +00:00
zeertzjq
151d6c7c41 test: add reasons to some skipped tests (#37632)
(cherry picked from commit 1e6c4ea896)
2026-02-06 01:17:06 +00:00
zeertzjq
3eef5752b3 fix(terminal): heap UAF if buffer deleted during TermRequest (#37612)
Problem:  Heap UAF if a terminal buffer is deleted during TermRequest in
          Normal mode.
Solution: Increment terminal refcount before triggering TermRequest, and
          destroy the terminal if the buffer is closed during that.
(cherry picked from commit b40880f88f)
2026-02-06 01:07:03 +00:00
zeertzjq
a3c8c593f2 test(terminal/cursor_spec): fix flaky test (#37715)
Problem:  Cursor visibility test may fail if the :sleep lasts too long.
Solution: Wait for the TermLeave autocommand to finish.
(cherry picked from commit b95e0a8d20)
2026-02-05 07:12:35 +00:00
zeertzjq
ba7456b91a test(terminal/cursor_spec): fix flaky test (#37681)
(cherry picked from commit 963162b338)
2026-02-05 07:02:49 +00:00
phanium
b1f2fe46cd fix: lsp.enable() don't work correctly inside FileType event #37538
Problem:
Two cases lsp.enable() won't work in the first FileType event
1. lsp.enable luals inside FileType or ftplugin/lua.lua, then:
```
nvim a.lua
```

2. lsp.enable luals inside FileType or ftplugin/lua.lua, then:
```
nvim -> :edit a.lua -> :mksession! | restart +qa! so Session.vim
```

Solution:
Currently `v:vim_did_enter` is used to detected two cases:
1. "maunally enabled" (lsp.enable() or `:lsp enable`)
2. "inside FileType event"

To detect 2. correctly we use did_filetype().

(cherry picked from commit fd45bc8cab)
2026-01-27 23:21:22 +00:00
zeertzjq
4b41c284ed fix(terminal): <Ignore> should be no-op (#37494)
(cherry picked from commit 196df35cca)
2026-01-22 01:58:47 +00:00
zeertzjq
40c974e689 fix(terminal): restore options properly when switching buffer (#37485)
(cherry picked from commit 25ce44845d)
2026-01-21 11:19:30 +00:00
zeertzjq
9ba985c250 test: add tests for #14379 2026-01-20 07:39:21 +08:00
Emanuel Krollmann
a512d43716 fix(autocmd): heap UAF with :bwipe in Syntax autocmd
Problem:
Creating an autocommand which executes `:bwipe` on the Syntax event
causes a heap-use-after-free.

Solution: set BF_SYN_SET flag before applying autocommands
(cherry picked from commit f36dd7557a)
2026-01-18 18:23:15 +00:00
zeertzjq
6ef1b655fe fix(normal): assertion failure with "gk" in narrow window (#37444)
When width1 and width2 are negative the assertion may fail. It seems
that adding a negative value to w_curswant won't cause any problems, so
just change the assertion.

(cherry picked from commit 41068c77aa)
2026-01-18 04:10:59 +00:00
Sean Dewar
1db945b584 fix(api): parse_expression crash with unopened ] and node
Problem: nvim_parse_expression null pointer dereference with unmatched ]
followed by a node.

Solution: if ast_stack was empty, set new_top_node_p to top of the stack after
pushing the list literal node; similar to what's done for curlies.

This bug was originally found by a Matrix user, but I couldn't remember how to
trigger it... Ran into the other crash while finding a repro. :P

(cherry picked from commit a5e5ec8910)
2026-01-17 13:48:49 +00:00
Sean Dewar
92849eacff fix(api): parse_expression crash with ident and curly
Problem: nvim_parse_expression null pointer dereference when parsing an
identifier followed by { with "highlight" parameter set to false.

Solution: only set opening_hl_idx if pstate->colors is not NULL.

Not added to parser_tests.lua as that uses highlight = true.

(cherry picked from commit 5226801be2)
2026-01-17 13:48:49 +00:00
zeertzjq
1e001b5c8d test: remove duplicate test (#37434)
This test is a copy of Test_bufunload_all() and requires too much
additional cleanup for the Windows log message.

(cherry picked from commit 8754118213)
2026-01-17 01:36:45 +00:00
Sean Dewar
10a1df2789 fix(api): nvim_get_option_value dummy buffer crashes
Problem: nvim_get_option_value with "filetype" set can crash if autocommands
open the dummy buffer in more windows, or if &bufhidden == "wipe".

Solution: Attempt to close all dummy buffer windows before wiping. Promote the
dummy buffer to a normal buffer if that fails.

(cherry picked from commit 7e2e116343)
2026-01-15 23:19:44 +00:00
Sean Dewar
6ce7b9b851 fix(api): autocmds mess up nvim_get_option_value's dummy buffer
Problem: When the "filetype" key is set for nvim_get_option_value, autocommands
can crash Nvim by prematurely wiping the dummy buffer, or cause options intended
for it to instead be set for unrelated buffers if switched during OptionSet.

Solution: Don't crash. Also quash side-effects from setting the buffer options.
(cherry picked from commit 3cb462a960)
2026-01-15 23:19:44 +00:00
zeertzjq
c469cba162 fix(channel): unreference list after callback finishes (#37358) 2026-01-12 08:36:14 +08:00
zeertzjq
f21c169a02 fix(lua): vim._with() doesn't save boolean options properly (#37354)
Problem:  vim._with() doesn't save boolean options with false values
          properly.
Solution: Use vim.F.if_nil().
(cherry picked from commit 94144d4678)
2026-01-11 12:30:12 +00:00
zeertzjq
2a3cd8dc80 fix(rpc): don't overwrite already received results on error (#37339)
This fixes a regression from cf6f60ce4d
(possibly), as before that commit a frame is popped from the call stack
immediately after its response is received.

Also fix leaking the allocated error messages.

(cherry picked from commit 39d8aa0a1a)
2026-01-11 10:49:03 +00:00
zeertzjq
ba600c495f fix(session): window sizes not stored with float windows (#37344)
(cherry picked from commit 2d3dc070ce)
2026-01-10 15:15:48 +00:00
zeertzjq
1b13864d97 test(server_notifications_spec): improve chanclose test (#37337)
Check that a pending event is actually cancelled, in place of the
nvim_subscribe that was removed in #28487.

(cherry picked from commit cb77bd1b86)
2026-01-10 04:37:36 +00:00
zeertzjq
800118e204 fix(terminal): :edit should respect 'bufhidden' with exited job (#37301) 2026-01-10 08:26:45 +08:00
zeertzjq
5e7af0ba01 fix(:ls): check for finished terminal properly (#37303)
Use terminal_running() instead of channel_job_running().

(cherry picked from commit 49d7f694a8)
2026-01-09 02:22:20 +00:00
zeertzjq
9f2b991331 vim-patch:9.1.2066: :wqall! doesn't close a terminal like :qall! does (#37314)
Problem:  :wqall! doesn't close a terminal buffer like :qall! does
          (after 8.0.1525).
Solution: Check eap->forceit (zeertzjq).

Ref: https://github.com/vim/vim/issues/2654#issuecomment-366803932

related: vim/vim#2654
related: neovim/neovim#14061
closes:  vim/vim#19129

d8558fdf4f
(cherry picked from commit 681d006549)
2026-01-09 00:15:54 +00:00
zeertzjq
ad70c2300e test(terminal/buffer_spec): fix flaky test (#37299)
It turns out that uv_write() doesn't queue the write if there are no
pending writes, so vim.uv.run() isn't needed to reproduce the crash.

(cherry picked from commit 0bd4d3f779)
2026-01-08 03:01:10 +00:00
zeertzjq
4f0e5678f3 test(buffer_updates_spec): move on_detach tests to its block (#37297)
(cherry picked from commit bfb70c03ff)
2026-01-08 02:30:29 +00:00
zeertzjq
e8c21a8b51 fix(langmap): assert failure on mapping to char >= 256 (#37291)
Usually 'langmap' is used to map keyboard characters to ASCII motions or
mappings. It's not entirely clear what the purpose of mapping to Unicode
characters is, but since there is no error for mapping between two chars
both >= 256, only give a warning that this will not work properly when
mapping from a char < 256 to a char >= 256.

(cherry picked from commit 16c1334399)
2026-01-08 01:15:01 +00:00
zeertzjq
cae3c838a7 fix(buffer): don't reuse 1-line terminal buffer (#37261)
Problem:  :edit and :enew may reuse a 1-line terminal buffer, causing
          the new buffer to still be a terminal buffer.
Solution: Don't reuse a terminal buffer, as it's not reused when it has
          more than 1 line.

After this change close_buffer() is the only place where buf_freeall()
can be called on a terminal buffer, so move the buf_close_terminal()
call into buf_freeall() to save some code. Furthermore, closing the
terminal in buf_freeall() is probably more correct anyway, as it is
"things allocated for a buffer that are related to the file".

Also, remove the useless check for on_detach callbacks deleting buffer.
Even if b_locked fails to prevent that, the crash will happen at the end
of buf_updates_unload() first. On the other hand, many other call sites
of buf_updates_unload() and other buffer_updates_* functions don't set
b_locked, which may be a problem as well...

(cherry picked from commit 23aa4853b3)
2026-01-06 09:09:23 +00:00
zeertzjq
ea871923eb fix(terminal): crash when TermClose switches back to terminal buffer
Problem:  Crash when deleting terminal buffer and TermClose switches
          back to the terminal buffer.
Solution: Set b_locked_split.

Co-authored-by: Sean Dewar <6256228+seandewar@users.noreply.github.com>
(cherry picked from commit ad85871ca1)
2026-01-05 23:53:27 +00:00
zeertzjq
2cc78732fc fix(terminal): crash when TermClose deletes other buffers
Problem:  Crash when deleting terminal buffer and TermClose deletes
          other buffers.
Solution: Close the terminal after restoring b_nwindows.
(cherry picked from commit 7297e9d339)
2026-01-05 23:53:27 +00:00
zeertzjq
26db87652e test(terminal): fix incorrect TermClose test
The test may wipe the wrong buffer if :bdelete switches to another one.

Also remove the builtin TermClose autocommand. It doesn't affect the
tests for now, but still it's better to avoid its interference.

(cherry picked from commit d42fa1753a)
2026-01-05 23:53:27 +00:00
zeertzjq
074d342f63 fix(terminal): avoid multiple terminals writing to same buffer (#37219)
Problem:  Calling termopen() or nvim_open_term() on a buffer with an
          existing terminal leads to two terminals writing to the same
          buffer if the terminal job is still running, or memory leak
          if the terminal job has exited.
Solution: Close the terminal if the terminal job has exited, otherwise
          report an error.
2026-01-05 13:54:08 +08:00
zeertzjq
f7e2554bfb fix(window): crash closing split if autocmds close other splits (#37233)
Problem:  Crash when closing a split window if autocmds close other
          split windows but there are still floating windows.
Solution: Bail out and give the window back its buffer.
2026-01-05 11:34:49 +08:00
Sean Dewar
a9ffdca528 fix(api): open_win leak from naughty autocommands
Problem: error set by win_set_buf may leak if autocommands immediately close the
new window.

Solution: free the error set by win_set_buf. (prefer nvim_open_win's error as
it's more important and will cause 0 to be returned)
2026-01-05 11:34:26 +08:00