aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Hahler <git@thequod.de>2018-07-14 18:23:08 +0200
committerJustin M. Keyes <justinkz@gmail.com>2018-08-28 10:20:19 +0200
commit643ef257b3e58928071de73aaae4b5e5911802ec (patch)
tree4209f269ec68291eb19dff3aa9d4ada8e454c88a
parent10e885bdfc42322dee3312b4373dc8f6653d2412 (diff)
downloadrneovim-643ef257b3e58928071de73aaae4b5e5911802ec.tar.gz
rneovim-643ef257b3e58928071de73aaae4b5e5911802ec.tar.bz2
rneovim-643ef257b3e58928071de73aaae4b5e5911802ec.zip
API: nvim_unsubscribe(): Handle unknown events #8745
close #8745
-rw-r--r--src/nvim/msgpack_rpc/channel.c5
-rw-r--r--test/functional/api/server_notifications_spec.lua7
2 files changed, 12 insertions, 0 deletions
diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c
index 3244d83a93..bb4aea0986 100644
--- a/src/nvim/msgpack_rpc/channel.c
+++ b/src/nvim/msgpack_rpc/channel.c
@@ -505,6 +505,11 @@ end:
static void unsubscribe(Channel *channel, char *event)
{
char *event_string = pmap_get(cstr_t)(event_strings, event);
+ if (!event_string) {
+ WLOG("RPC: ch %" PRIu64 ": tried to unsubscribe unknown event '%s'",
+ channel->id, event);
+ return;
+ }
pmap_del(cstr_t)(channel->rpc.subscribed_events, event_string);
map_foreach_value(channels, channel, {
diff --git a/test/functional/api/server_notifications_spec.lua b/test/functional/api/server_notifications_spec.lua
index 1d64ae7103..29cd38ef0d 100644
--- a/test/functional/api/server_notifications_spec.lua
+++ b/test/functional/api/server_notifications_spec.lua
@@ -65,4 +65,11 @@ describe('notify', function()
eq(nest_level, act_nest_level)
end)
end)
+
+ it('unsubscribe non-existing event #8745', function()
+ nvim('subscribe', 'event1')
+ nvim('unsubscribe', 'doesnotexist')
+ nvim('unsubscribe', 'event1')
+ eq(2, eval('1+1')) -- Still alive?
+ end)
end)