@@ -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 );
0 commit comments