patch 7.4.1105
Problem: When using slices there is a mixup of variable name and namespace.
Solution: Recognize variables that can't be a namespace. (Hirohito Higashi)
diff --git a/src/eval.c b/src/eval.c
index 1e2a041..d4e3b9e 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -115,6 +115,8 @@
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 @@
/* 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 @@
int mb_nest = 0;
int br_nest = 0;
char_u *p;
+ int len;
if (expr_start != NULL)
{
@@ -20801,6 +20814,15 @@
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)
{
diff --git a/src/testdir/test_eval.in b/src/testdir/test_eval.in
index 087e609..84f26ba 100644
--- a/src/testdir/test_eval.in
+++ b/src/testdir/test_eval.in
@@ -218,6 +218,24 @@
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()
diff --git a/src/testdir/test_eval.ok b/src/testdir/test_eval.ok
index cda425c..9ffa541 100644
--- a/src/testdir/test_eval.ok
+++ b/src/testdir/test_eval.ok
Binary files differ
diff --git a/src/version.c b/src/version.c
index baecfc7..f74281d 100644
--- a/src/version.c
+++ b/src/version.c
@@ -742,6 +742,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1105,
+/**/
1104,
/**/
1103,