vim-patch:8.2.3743: ":sign" can add a highlight group without a name

Problem:    ":sign" can add a highlight group without a name.
Solution:   Give an error if the group name is missing. (closes vim/vim#9280)
5e18ccc60b
This commit is contained in:
James McCoy 2021-12-05 21:39:37 -05:00
parent e8f9262125
commit d0b3efb7db
No known key found for this signature in database
GPG Key ID: DFE691AE331BA3DB
3 changed files with 31 additions and 0 deletions

View File

@ -997,6 +997,8 @@ EXTERN char e_non_empty_string_required[] INIT(= N_("E1142: Non-empty string req
EXTERN char e_cannot_define_autocommands_for_all_events[] INIT(= N_("E1155: Cannot define autocommands for ALL events")); EXTERN char e_cannot_define_autocommands_for_all_events[] INIT(= N_("E1155: Cannot define autocommands for ALL events"));
EXTERN char e_group_name_missing_for_str[] INIT(= N_("E1249: Group name missing for %s"));
EXTERN char top_bot_msg[] INIT(= N_("search hit TOP, continuing at BOTTOM")); EXTERN char top_bot_msg[] INIT(= N_("search hit TOP, continuing at BOTTOM"));
EXTERN char bot_top_msg[] INIT(= N_("search hit BOTTOM, continuing at TOP")); EXTERN char bot_top_msg[] INIT(= N_("search hit BOTTOM, continuing at TOP"));

View File

@ -1132,6 +1132,15 @@ linenr_T sign_jump(int sign_id, char_u *sign_group, buf_T *buf)
return lnum; return lnum;
} }
static int check_empty_group(size_t len, char *name)
{
if (len == 0) {
semsg(_(e_group_name_missing_for_str), name);
return FAIL;
}
return OK;
}
/// ":sign define {name} ..." command /// ":sign define {name} ..." command
static void sign_define_cmd(char_u *sign_name, char_u *cmdline) static void sign_define_cmd(char_u *sign_name, char_u *cmdline)
{ {
@ -1160,15 +1169,31 @@ static void sign_define_cmd(char_u *sign_name, char_u *cmdline)
text = vim_strnsave(arg, (size_t)(p - arg)); text = vim_strnsave(arg, (size_t)(p - arg));
} else if (STRNCMP(arg, "linehl=", 7) == 0) { } else if (STRNCMP(arg, "linehl=", 7) == 0) {
arg += 7; arg += 7;
if (check_empty_group(p - arg, "linehl") == FAIL) {
failed = true;
break;
}
linehl = vim_strnsave(arg, (size_t)(p - arg)); linehl = vim_strnsave(arg, (size_t)(p - arg));
} else if (STRNCMP(arg, "texthl=", 7) == 0) { } else if (STRNCMP(arg, "texthl=", 7) == 0) {
arg += 7; arg += 7;
if (check_empty_group(p - arg, "texthl") == FAIL) {
failed = true;
break;
}
texthl = vim_strnsave(arg, (size_t)(p - arg)); texthl = vim_strnsave(arg, (size_t)(p - arg));
} else if (STRNCMP(arg, "culhl=", 6) == 0) { } else if (STRNCMP(arg, "culhl=", 6) == 0) {
arg += 6; arg += 6;
if (check_empty_group(p - arg, "culhl") == FAIL) {
failed = true;
break;
}
culhl = vim_strnsave(arg, (size_t)(p - arg)); culhl = vim_strnsave(arg, (size_t)(p - arg));
} else if (STRNCMP(arg, "numhl=", 6) == 0) { } else if (STRNCMP(arg, "numhl=", 6) == 0) {
arg += 6; arg += 6;
if (check_empty_group(p - arg, "numhl") == FAIL) {
failed = true;
break;
}
numhl = vim_strnsave(arg, (size_t)(p - arg)); numhl = vim_strnsave(arg, (size_t)(p - arg));
} else { } else {
semsg(_(e_invarg2), arg); semsg(_(e_invarg2), arg);

View File

@ -126,6 +126,10 @@ func Test_sign()
" call assert_fails("sign define Sign4 text= linehl=Comment", 'E239:') " call assert_fails("sign define Sign4 text= linehl=Comment", 'E239:')
call assert_fails("sign define Sign4 text=\\ ab linehl=Comment", 'E239:') call assert_fails("sign define Sign4 text=\\ ab linehl=Comment", 'E239:')
call assert_fails("sign define Sign4 linehl=", 'E1249: Group name missing for linehl')
call assert_fails("sign define Sign4 culhl=", 'E1249: Group name missing for culhl')
call assert_fails("sign define Sign4 texthl=", 'E1249: Group name missing for texthl')
" define sign with whitespace " define sign with whitespace
sign define Sign4 text=\ X linehl=Comment sign define Sign4 text=\ X linehl=Comment
sign undefine Sign4 sign undefine Sign4