Allow to escape all expandable chars.
authorDaniel Carl <danielcarl@gmx.de>
Wed, 4 Jun 2014 22:45:53 +0000 (00:45 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Wed, 4 Jun 2014 22:45:53 +0000 (00:45 +0200)
The expandable chars are always allowed to be escaped by a \ if the expansion
type is active.

src/ex.c
src/util.c

index 17d73bf..8596a45 100644 (file)
--- a/src/ex.c
+++ b/src/ex.c
@@ -645,25 +645,20 @@ static gboolean parse_lhs(const char **input, ExArg *arg)
 static gboolean parse_rhs(const char **input, ExArg *arg)
 {
     int expflags, flags;
-    const char *quoteable;
 
     if (!*input || !**input) {
         return false;
     }
 
-    if (arg->flags & EX_FLAG_EXP) {
-        expflags  = UTIL_EXP_TILDE|UTIL_EXP_DOLLAR|UTIL_EXP_SPECIAL;
-        quoteable = "|~$%\\";
-    } else {
-        expflags  = 0;
-        quoteable = "|\\";
-    }
+    expflags = (arg->flags & EX_FLAG_EXP)
+        ? UTIL_EXP_TILDE|UTIL_EXP_DOLLAR|UTIL_EXP_SPECIAL
+        : 0;
     flags = expflags;
 
     /* get char until the end of command */
     while (**input && **input != '\n' && **input != '|') {
         /* check for expansion placeholder */
-        util_parse_expansion(input, arg->rhs, flags, quoteable);
+        util_parse_expansion(input, arg->rhs, flags, "|\\");
 
         if (VB_IS_SEPARATOR(**input)) {
             /* add tilde expansion for next loop needs to be first char or to
index 078b718..0dcd0c3 100644 (file)
@@ -352,7 +352,7 @@ char *util_expand(const char *src, int expflags)
     int flags    = expflags;
 
     while (**input) {
-        util_parse_expansion(input, dst, flags, "~$%\\");
+        util_parse_expansion(input, dst, flags, "\\");
         if (VB_IS_SEPARATOR(**input)) {
             /* after space the tilde expansion is allowed */
             flags = expflags;
@@ -379,7 +379,7 @@ char *util_expand(const char *src, int expflags)
  * @input:    String pointer with the content to be parsed.
  * @str:      GString that will be filled with expanded content.
  * @flags     Flags that determine which expansion are processed.
- * @quoteable String of chars that are allowed to be escaped by \.
+ * @quoteable String of chars that are additionally escapable by \.
  * Returns true if input started with expandable pattern.
  */
 gboolean util_parse_expansion(const char **input, GString *str, int flags,
@@ -471,7 +471,11 @@ gboolean util_parse_expansion(const char **input, GString *str, int flags,
             if (!*input) {
                 /* if input ends here - use only the quote char */
                 g_string_append_c(str, quote);
-            } else if (strchr(quoteable, **input)) {
+            } else if (strchr(quoteable, **input)
+                || (flags & UTIL_EXP_TILDE && **input == '~')
+                || (flags & UTIL_EXP_DOLLAR && **input == '$')
+                || (flags & UTIL_EXP_SPECIAL && **input == '%')
+            ) {
                 /* escaped char becomes only char */
                 g_string_append_c(str, **input);
             } else {