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 #9280)
diff --git a/src/errors.h b/src/errors.h
index 96aef67..e035f07 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -694,3 +694,5 @@
INIT(= N_("E1247: Line number out of range"));
EXTERN char e_closure_called_from_invalid_context[]
INIT(= N_("E1248: Closure called from invalid context"));
+EXTERN char e_group_name_missing_for_str[]
+ INIT(= N_("E1249: Group name missing for %s"));
diff --git a/src/sign.c b/src/sign.c
index a4c8967..66a29db 100644
--- a/src/sign.c
+++ b/src/sign.c
@@ -1295,6 +1295,17 @@
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
*/
@@ -1330,16 +1341,31 @@
else if (STRNCMP(arg, "linehl=", 7) == 0)
{
arg += 7;
+ if (check_empty_group(p - arg, "linehl") == FAIL)
+ {
+ failed = TRUE;
+ break;
+ }
linehl = vim_strnsave(arg, p - arg);
}
else if (STRNCMP(arg, "texthl=", 7) == 0)
{
arg += 7;
+ if (check_empty_group(p - arg, "texthl") == FAIL)
+ {
+ failed = TRUE;
+ break;
+ }
texthl = vim_strnsave(arg, p - arg);
}
else if (STRNCMP(arg, "culhl=", 6) == 0)
{
arg += 6;
+ if (check_empty_group(p - arg, "culhl") == FAIL)
+ {
+ failed = TRUE;
+ break;
+ }
culhl = vim_strnsave(arg, p - arg);
}
else
diff --git a/src/testdir/test_signs.vim b/src/testdir/test_signs.vim
index 80f7160..18a6edc 100644
--- a/src/testdir/test_signs.vim
+++ b/src/testdir/test_signs.vim
@@ -126,6 +126,10 @@
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 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
sign define Sign4 text=\ X linehl=Comment
sign undefine Sign4
diff --git a/src/version.c b/src/version.c
index 531642e..cd7a964 100644
--- a/src/version.c
+++ b/src/version.c
@@ -754,6 +754,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 3743,
+/**/
3742,
/**/
3741,