diff options
author | ii14 <59243201+ii14@users.noreply.github.com> | 2023-10-09 11:50:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-09 02:50:44 -0700 |
commit | 139e6f68f937b9efcadf2709ee1c83213d3266fa (patch) | |
tree | 7daa6dbc0f9c207980a2757620cfcc2c6f6f42d9 /src/nvim/autocmd.c | |
parent | 8e932480f61d6101bf8bea1abc07ed93826221fd (diff) | |
download | rneovim-139e6f68f937b9efcadf2709ee1c83213d3266fa.tar.gz rneovim-139e6f68f937b9efcadf2709ee1c83213d3266fa.tar.bz2 rneovim-139e6f68f937b9efcadf2709ee1c83213d3266fa.zip |
fix(autocmd): API functions accept garbage after event name #25523
"VimEnter foo" was accepted as a valid event name for "VimEnter".
Events delimited with commas, eg. "VimEnter,BufRead", were also
accepted, even though only the first event was actually parsed.
Co-authored-by: ii14 <ii14@users.noreply.github.com>
Diffstat (limited to 'src/nvim/autocmd.c')
-rw-r--r-- | src/nvim/autocmd.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index 9f7c599164..2537269c5c 100644 --- a/src/nvim/autocmd.c +++ b/src/nvim/autocmd.c @@ -597,9 +597,9 @@ bool is_aucmd_win(win_T *win) return false; } -// Return the event number for event name "start". -// Return NUM_EVENTS if the event name was not found. -// Return a pointer to the next event name in "end". +/// Return the event number for event name "start". +/// Return NUM_EVENTS if the event name was not found. +/// Return a pointer to the next event name in "end". event_T event_name2nr(const char *start, char **end) { const char *p; @@ -623,6 +623,18 @@ event_T event_name2nr(const char *start, char **end) return event_names[i].event; } +/// Return the event number for event name "str". +/// Return NUM_EVENTS if the event name was not found. +event_T event_name2nr_str(String str) +{ + for (int i = 0; event_names[i].name != NULL; i++) { + if (str.size == event_names[i].len && STRNICMP(str.data, event_names[i].name, str.size) == 0) { + return event_names[i].event; + } + } + return NUM_EVENTS; +} + /// Return the name for event /// /// @param[in] event Event to return name for. |