]> granicus.if.org Git - vim/commitdiff
patch 7.4.1105 v7.4.1105
authorBram Moolenaar <Bram@vim.org>
Sat, 16 Jan 2016 15:49:28 +0000 (16:49 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 16 Jan 2016 15:49:28 +0000 (16:49 +0100)
Problem:    When using slices there is a mixup of variable name and namespace.
Solution:   Recognize variables that can't be a namespace. (Hirohito Higashi)

src/eval.c
src/testdir/test_eval.in
src/testdir/test_eval.ok
src/version.c

index 1e2a0419e6bb07666d63cb67890a37c9be7b407f..d4e3b9ef59512afb8470dfce9fc4c9701155b7f6 100644 (file)
@@ -115,6 +115,8 @@ static char *e_illvar = N_("E461: Illegal variable name: %s");
 static char *e_float_as_string = N_("E806: using Float as a String");
 #endif
 
+#define NAMESPACE_CHAR (char_u *)"abglstvw"
+
 static dictitem_T      globvars_var;           /* variable used for g: */
 #define globvarht globvardict.dv_hashtab
 
@@ -20666,7 +20668,17 @@ get_id_len(arg)
 
     /* Find the end of the name. */
     for (p = *arg; eval_isnamec(*p); ++p)
-       ;
+    {
+       if (*p == ':')
+       {
+           /* "s:" is start of "s:var", but "n:" is not and can be used in
+            * slice "[n:]".  Also "xx:" is not a namespace. */
+           len = (int)(p - *arg);
+           if ((len == 1 && vim_strchr(NAMESPACE_CHAR, **arg) == NULL)
+                   || len > 1)
+               break;
+       }
+    }
     if (p == *arg)         /* no name found */
        return 0;
 
@@ -20766,6 +20778,7 @@ find_name_end(arg, expr_start, expr_end, flags)
     int                mb_nest = 0;
     int                br_nest = 0;
     char_u     *p;
+    int                len;
 
     if (expr_start != NULL)
     {
@@ -20801,6 +20814,15 @@ find_name_end(arg, expr_start, expr_end, flags)
            if (*p == NUL)
                break;
        }
+       else if (br_nest == 0 && mb_nest == 0 && *p == ':')
+       {
+           /* "s:" is start of "s:var", but "n:" is not and can be used in
+            * slice "[n:]".  Also "xx:" is not a namespace. */
+           len = (int)(p - arg);
+           if ((len == 1 && vim_strchr(NAMESPACE_CHAR, *arg) == NULL)
+                   || len > 1)
+               break;
+       }
 
        if (mb_nest == 0)
        {
index 087e6099ac70aa6820fd10d24b35b958df4e1fb5..84f26bafc1f608b66609b289fb19e33457434cc7 100644 (file)
@@ -218,6 +218,24 @@ endfun
 0:call setpos('.', sp)
 jyl:$put
 :"
+:" substring and variable name
+:let str = 'abcdef'
+:let n = 3
+:$put =str[n:]
+:$put =str[:n]
+:$put =str[n:n]
+:unlet n
+:let nn = 3
+:$put =str[nn:]
+:$put =str[:nn]
+:$put =str[nn:nn]
+:unlet nn
+:let b:nn = 4
+:$put =str[b:nn:]
+:$put =str[:b:nn]
+:$put =str[b:nn:b:nn]
+:unlet b:nn
+:"
 :/^start:/+1,$wq! test.out
 :" vim: et ts=4 isk-=\: fmr=???,???
 :call getchar()
index cda425c92e30762a9c5949964be411a517884f0d..9ffa54157fabaf710b0af4f13d191292d206e785 100644 (file)
Binary files a/src/testdir/test_eval.ok and b/src/testdir/test_eval.ok differ
index baecfc7d006bf5392d815590671cd8fa8e4a32d4..f74281d797609d63ccd0e12ed3a71aa0b4d6ac24 100644 (file)
@@ -741,6 +741,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1105,
 /**/
     1104,
 /**/