Skip to content

Commit f169304

Browse files
committed
updated for version 7.3.1295
Problem: glob() and globpath() do not handle escaped special characters properly. Solution: Handle escaped characters differently. (Adnan Zafar)
1 parent 41f2189 commit f169304

File tree

11 files changed

+89
-12
lines changed

11 files changed

+89
-12
lines changed

src/fileio.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10301,15 +10301,19 @@ file_pat_to_reg_pat(pat, pat_end, allow_dirs, no_bslash)
1030110301
* foo\,bar -> foo,bar
1030210302
* foo\ bar -> foo bar
1030310303
* Don't unescape \, * and others that are also special in a
10304-
* regexp. */
10304+
* regexp.
10305+
* An escaped { must be unescaped since we use magic not
10306+
* verymagic.
10307+
*/
1030510308
if (*++p == '?'
1030610309
#ifdef BACKSLASH_IN_FILENAME
1030710310
&& no_bslash
1030810311
#endif
1030910312
)
1031010313
reg_pat[i++] = '?';
1031110314
else
10312-
if (*p == ',' || *p == '%' || *p == '#' || *p == ' ')
10315+
if (*p == ',' || *p == '%' || *p == '#'
10316+
|| *p == ' ' || *p == '{')
1031310317
reg_pat[i++] = *p;
1031410318
else
1031510319
{

src/misc1.c

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10457,6 +10457,54 @@ remove_duplicates(gap)
1045710457
}
1045810458
#endif
1045910459

10460+
static int has_env_var __ARGS((char_u *p));
10461+
10462+
/*
10463+
* Return TRUE if "p" contains what looks like an environment variable.
10464+
* Allowing for escaping.
10465+
*/
10466+
static int
10467+
has_env_var(p)
10468+
char_u *p;
10469+
{
10470+
for ( ; *p; mb_ptr_adv(p))
10471+
{
10472+
if (*p == '\\' && p[1] != NUL)
10473+
++p;
10474+
else if (vim_strchr((char_u *)
10475+
#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
10476+
"$%"
10477+
#else
10478+
"$"
10479+
#endif
10480+
, *p) != NULL)
10481+
return TRUE;
10482+
}
10483+
return FALSE;
10484+
}
10485+
10486+
#ifdef SPECIAL_WILDCHAR
10487+
static int has_special_wildchar __ARGS((char_u *p));
10488+
10489+
/*
10490+
* Return TRUE if "p" contains a special wildcard character.
10491+
* Allowing for escaping.
10492+
*/
10493+
static int
10494+
has_special_wildchar(p)
10495+
char_u *p;
10496+
{
10497+
for ( ; *p; mb_ptr_adv(p))
10498+
{
10499+
if (*p == '\\' && p[1] != NUL)
10500+
++p;
10501+
else if (vim_strchr((char_u *)SPECIAL_WILDCHAR, *p) != NULL)
10502+
return TRUE;
10503+
}
10504+
return FALSE;
10505+
}
10506+
#endif
10507+
1046010508
/*
1046110509
* Generic wildcard expansion code.
1046210510
*
@@ -10507,7 +10555,7 @@ gen_expand_wildcards(num_pat, pat, num_file, file, flags)
1050710555
*/
1050810556
for (i = 0; i < num_pat; i++)
1050910557
{
10510-
if (vim_strpbrk(pat[i], (char_u *)SPECIAL_WILDCHAR) != NULL
10558+
if (has_special_wildchar(pat[i])
1051110559
# ifdef VIM_BACKTICK
1051210560
&& !(vim_backtick(pat[i]) && pat[i][1] == '=')
1051310561
# endif
@@ -10537,7 +10585,7 @@ gen_expand_wildcards(num_pat, pat, num_file, file, flags)
1053710585
/*
1053810586
* First expand environment variables, "~/" and "~user/".
1053910587
*/
10540-
if (vim_strchr(p, '$') != NULL || *p == '~')
10588+
if (has_env_var(p) || *p == '~')
1054110589
{
1054210590
p = expand_env_save_opt(p, TRUE);
1054310591
if (p == NULL)
@@ -10548,7 +10596,7 @@ gen_expand_wildcards(num_pat, pat, num_file, file, flags)
1054810596
* variable, use the shell to do that. Discard previously
1054910597
* found file names and start all over again.
1055010598
*/
10551-
else if (vim_strchr(p, '$') != NULL || *p == '~')
10599+
else if (has_env_var(p) || *p == '~')
1055210600
{
1055310601
vim_free(p);
1055410602
ga_clear_strings(&ga);

src/testdir/Make_amiga.mak

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ SCRIPTS = test1.out test3.out test4.out test5.out test6.out \
3333
test76.out test77.out test78.out test79.out test80.out \
3434
test81.out test82.out test83.out test84.out test88.out \
3535
test89.out test90.out test91.out test92.out test93.out \
36-
test94.out test95.out test96.out
36+
test94.out test95.out test96.out test97.out
3737

3838
.SUFFIXES: .in .out
3939

@@ -146,3 +146,4 @@ test93.out: test93.in
146146
test94.out: test94.in
147147
test95.out: test95.in
148148
test96.out: test96.in
149+
test97.out: test97.in

src/testdir/Make_dos.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ SCRIPTS = test3.out test4.out test5.out test6.out test7.out \
3232
test79.out test80.out test81.out test82.out test83.out \
3333
test84.out test85.out test86.out test87.out test88.out \
3434
test89.out test90.out test91.out test92.out test93.out \
35-
test94.out test95.out test96.out
35+
test94.out test95.out test96.out test97.out
3636

3737
SCRIPTS32 = test50.out test70.out
3838

src/testdir/Make_ming.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ SCRIPTS = test3.out test4.out test5.out test6.out test7.out \
5252
test79.out test80.out test81.out test82.out test83.out \
5353
test84.out test85.out test86.out test87.out test88.out \
5454
test89.out test90.out test91.out test92.out test93.out \
55-
test94.out test95.out test96.out
55+
test94.out test95.out test96.out test97.out
5656

5757
SCRIPTS32 = test50.out test70.out
5858

src/testdir/Make_os2.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ SCRIPTS = test1.out test3.out test4.out test5.out test6.out \
3333
test76.out test77.out test78.out test79.out test80.out \
3434
test81.out test82.out test83.out test84.out test88.out \
3535
test89.out test90.out test91.out test92.out test93.out \
36-
test94.out test95.out test96.out
36+
test94.out test95.out test96.out test97.out
3737

3838
.SUFFIXES: .in .out
3939

src/testdir/Make_vms.mms

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Authors: Zoltan Arpadffy, <[email protected]>
55
# Sandor Kopanyi, <[email protected]>
66
#
7-
# Last change: 2013 Jul 01
7+
# Last change: 2013 Jul 03
88
#
99
# This has been tested on VMS 6.2 to 8.3 on DEC Alpha, VAX and IA64.
1010
# Edit the lines in the Configuration section below to select.
@@ -78,7 +78,7 @@ SCRIPT = test1.out test2.out test3.out test4.out test5.out \
7878
test77.out test78.out test79.out test80.out test81.out \
7979
test82.out test83.out test84.out test88.out test89.out \
8080
test90.out test91.out test92.out test93.out test94.out \
81-
test95.out test96.out
81+
test95.out test96.out test97.out
8282

8383
# Known problems:
8484
# Test 30: a problem around mac format - unknown reason

src/testdir/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ SCRIPTS = test1.out test2.out test3.out test4.out test5.out test6.out \
2929
test79.out test80.out test81.out test82.out test83.out \
3030
test84.out test85.out test86.out test87.out test88.out \
3131
test89.out test90.out test91.out test92.out test93.out \
32-
test94.out test95.out test96.out
32+
test94.out test95.out test96.out test97.out
3333

3434
SCRIPTS_GUI = test16.out
3535

src/testdir/test97.in

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Test whether glob()/globpath() return correct results with certain escaped
2+
characters.
3+
4+
STARTTEST
5+
:so small.vim
6+
:set shell=doesnotexist
7+
:e test.out
8+
:put =glob('Xxx\{')
9+
:put =glob('Xxx\$')
10+
:w! Xxx{
11+
:w! Xxx\$
12+
:put =glob('Xxx\{')
13+
:put =glob('Xxx\$')
14+
:w
15+
:qa!
16+
ENDTEST
17+

src/testdir/test97.ok

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
3+
4+
Xxx{
5+
Xxx$

0 commit comments

Comments
 (0)