]> granicus.if.org Git - vim/commitdiff
patch 8.2.3743: ":sign" can add a highlight group without a name v8.2.3743
authorBram Moolenaar <Bram@vim.org>
Sun, 5 Dec 2021 13:02:50 +0000 (13:02 +0000)
committerBram Moolenaar <Bram@vim.org>
Sun, 5 Dec 2021 13:02:50 +0000 (13:02 +0000)
Problem:    ":sign" can add a highlight group without a name.
Solution:   Give an error if the group name is missing. (closes #9280)

src/errors.h
src/sign.c
src/testdir/test_signs.vim
src/version.c

index 96aef67fcb9ef579b7d935cd513ea42277570ae3..e035f076d83d5eeddcd416d206f1a71cbb0ad01f 100644 (file)
@@ -694,3 +694,5 @@ EXTERN char e_line_number_out_of_range[]
        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"));
index a4c89679b44feabbd42134e113f6cad891064cd2..66a29db1d711ac61aa84789f8ab8d90512e4a266 100644 (file)
@@ -1295,6 +1295,17 @@ sign_jump(int sign_id, char_u *sign_group, buf_T *buf)
     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 @@ sign_define_cmd(char_u *sign_name, char_u *cmdline)
        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
index 80f7160b100a7e1e476262321f722df897c67213..18a6edc772907f7792550438e390719ea7bfd484 100644 (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=\\ 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
index 531642ec0057e29434dcc17f1320d6ad95a30e48..cd7a964022cbe58cd8a93219eae332db9caf38c7 100644 (file)
@@ -753,6 +753,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3743,
 /**/
     3742,
 /**/