From beb8f484891f5361cc2ee757b93b4e4aba228612 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 5 May 2022 07:23:27 +0800 Subject: vim-patch:8.2.4867: listing of mapping with K_SPECIAL is wrong (#18419) Problem: Listing of mapping with K_SPECIAL is wrong. Solution: Adjust escaping of special characters. (closes vim/vim#10351) https://github.com/vim/vim/commit/ac402f4d64bec6b6efd809fef52f5b34627bf947 Avoid overshadowing. Cherry-pick Test_list_mapping() from Vim patches 8.2.{0148,2994}. Fix rhs_is_noop. --- src/nvim/message.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'src/nvim/message.c') diff --git a/src/nvim/message.c b/src/nvim/message.c index f0ef4e1d4f..cdcbcc6700 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -1671,11 +1671,13 @@ const char *str2special(const char **const sp, const bool replace_spaces, const { static char buf[7]; - // Try to un-escape a multi-byte character. Return the un-escaped - // string if it is a multi-byte character. - const char *const p = mb_unescape(sp); - if (p != NULL) { - return p; + { + // Try to un-escape a multi-byte character. Return the un-escaped + // string if it is a multi-byte character. + const char *const p = mb_unescape(sp); + if (p != NULL) { + return p; + } } const char *str = *sp; @@ -1698,18 +1700,24 @@ const char *str2special(const char **const sp, const bool replace_spaces, const } if (!IS_SPECIAL(c)) { - const int len = utf_ptr2len((const char_u *)str); + *sp = str; + // Try to un-escape a multi-byte character after modifiers. + const char *p = mb_unescape(sp); - // Check for an illegal byte. - if (MB_BYTE2LEN((uint8_t)(*str)) > len) { - transchar_nonprint(curbuf, (char_u *)buf, c); - *sp = str + 1; - return buf; + if (p == NULL) { + const int len = utf_ptr2len((const char_u *)str); + // Check for an illegal byte. + if (MB_BYTE2LEN((uint8_t)(*str)) > len) { + transchar_nonprint(curbuf, (char_u *)buf, c); + *sp = str + 1; + return buf; + } + *sp = str + len; + p = str; } - // Since 'special' is TRUE the multi-byte character 'c' will be + // Since 'special' is true the multi-byte character 'c' will be // processed by get_special_key_name(). - c = utf_ptr2char((const char_u *)str); - *sp = str + len; + c = utf_ptr2char((const char_u *)p); } else { *sp = str + 1; } -- cgit