diff src/misc1.c @ 5104:93cccad6a26b v7.3.1295

updated for version 7.3.1295 Problem: glob() and globpath() do not handle escaped special characters properly. Solution: Handle escaped characters differently. (Adnan Zafar)
author Bram Moolenaar <bram@vim.org>
date Wed, 03 Jul 2013 16:53:03 +0200
parents 8bbd0ff486b3
children 25f67b62afd8
line wrap: on
line diff
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -10457,6 +10457,54 @@ remove_duplicates(gap)
 }
 #endif
 
+static int has_env_var __ARGS((char_u *p));
+
+/*
+ * Return TRUE if "p" contains what looks like an environment variable.
+ * Allowing for escaping.
+ */
+    static int
+has_env_var(p)
+    char_u *p;
+{
+    for ( ; *p; mb_ptr_adv(p))
+    {
+	if (*p == '\\' && p[1] != NUL)
+	    ++p;
+	else if (vim_strchr((char_u *)
+#if defined(MSDOS) || defined(MSWIN) || defined(OS2)
+				    "$%"
+#else
+				    "$"
+#endif
+					, *p) != NULL)
+	    return TRUE;
+    }
+    return FALSE;
+}
+
+#ifdef SPECIAL_WILDCHAR
+static int has_special_wildchar __ARGS((char_u *p));
+
+/*
+ * Return TRUE if "p" contains a special wildcard character.
+ * Allowing for escaping.
+ */
+    static int
+has_special_wildchar(p)
+    char_u  *p;
+{
+    for ( ; *p; mb_ptr_adv(p))
+    {
+	if (*p == '\\' && p[1] != NUL)
+	    ++p;
+	else if (vim_strchr((char_u *)SPECIAL_WILDCHAR, *p) != NULL)
+	    return TRUE;
+    }
+    return FALSE;
+}
+#endif
+
 /*
  * Generic wildcard expansion code.
  *
@@ -10507,7 +10555,7 @@ gen_expand_wildcards(num_pat, pat, num_f
      */
     for (i = 0; i < num_pat; i++)
     {
-	if (vim_strpbrk(pat[i], (char_u *)SPECIAL_WILDCHAR) != NULL
+	if (has_special_wildchar(pat[i])
 # ifdef VIM_BACKTICK
 		&& !(vim_backtick(pat[i]) && pat[i][1] == '=')
 # endif
@@ -10537,7 +10585,7 @@ gen_expand_wildcards(num_pat, pat, num_f
 	    /*
 	     * First expand environment variables, "~/" and "~user/".
 	     */
-	    if (vim_strchr(p, '$') != NULL || *p == '~')
+	    if (has_env_var(p) || *p == '~')
 	    {
 		p = expand_env_save_opt(p, TRUE);
 		if (p == NULL)
@@ -10548,7 +10596,7 @@ gen_expand_wildcards(num_pat, pat, num_f
 		 * variable, use the shell to do that.  Discard previously
 		 * found file names and start all over again.
 		 */
-		else if (vim_strchr(p, '$') != NULL || *p == '~')
+		else if (has_env_var(p) || *p == '~')
 		{
 		    vim_free(p);
 		    ga_clear_strings(&ga);