Skip to content

Commit 9bbf63d

Browse files
committed
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)
1 parent 4e640bd commit 9bbf63d

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

src/eval.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ static char *e_illvar = N_("E461: Illegal variable name: %s");
115115
static char *e_float_as_string = N_("E806: using Float as a String");
116116
#endif
117117

118+
#define NAMESPACE_CHAR (char_u *)"abglstvw"
119+
118120
static dictitem_T globvars_var; /* variable used for g: */
119121
#define globvarht globvardict.dv_hashtab
120122

@@ -20666,7 +20668,17 @@ get_id_len(arg)
2066620668

2066720669
/* Find the end of the name. */
2066820670
for (p = *arg; eval_isnamec(*p); ++p)
20669-
;
20671+
{
20672+
if (*p == ':')
20673+
{
20674+
/* "s:" is start of "s:var", but "n:" is not and can be used in
20675+
* slice "[n:]". Also "xx:" is not a namespace. */
20676+
len = (int)(p - *arg);
20677+
if ((len == 1 && vim_strchr(NAMESPACE_CHAR, **arg) == NULL)
20678+
|| len > 1)
20679+
break;
20680+
}
20681+
}
2067020682
if (p == *arg) /* no name found */
2067120683
return 0;
2067220684

@@ -20766,6 +20778,7 @@ find_name_end(arg, expr_start, expr_end, flags)
2076620778
int mb_nest = 0;
2076720779
int br_nest = 0;
2076820780
char_u *p;
20781+
int len;
2076920782

2077020783
if (expr_start != NULL)
2077120784
{
@@ -20801,6 +20814,15 @@ find_name_end(arg, expr_start, expr_end, flags)
2080120814
if (*p == NUL)
2080220815
break;
2080320816
}
20817+
else if (br_nest == 0 && mb_nest == 0 && *p == ':')
20818+
{
20819+
/* "s:" is start of "s:var", but "n:" is not and can be used in
20820+
* slice "[n:]". Also "xx:" is not a namespace. */
20821+
len = (int)(p - arg);
20822+
if ((len == 1 && vim_strchr(NAMESPACE_CHAR, *arg) == NULL)
20823+
|| len > 1)
20824+
break;
20825+
}
2080420826

2080520827
if (mb_nest == 0)
2080620828
{

src/testdir/test_eval.in

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,24 @@ endfun
218218
0:call setpos('.', sp)
219219
jyl:$put
220220
:"
221+
:" substring and variable name
222+
:let str = 'abcdef'
223+
:let n = 3
224+
:$put =str[n:]
225+
:$put =str[:n]
226+
:$put =str[n:n]
227+
:unlet n
228+
:let nn = 3
229+
:$put =str[nn:]
230+
:$put =str[:nn]
231+
:$put =str[nn:nn]
232+
:unlet nn
233+
:let b:nn = 4
234+
:$put =str[b:nn:]
235+
:$put =str[:b:nn]
236+
:$put =str[b:nn:b:nn]
237+
:unlet b:nn
238+
:"
221239
:/^start:/+1,$wq! test.out
222240
:" vim: et ts=4 isk-=\: fmr=???,???
223241
:call getchar()

src/testdir/test_eval.ok

33 Bytes
Binary file not shown.

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ static char *(features[]) =
741741

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
1105,
744746
/**/
745747
1104,
746748
/**/

0 commit comments

Comments
 (0)