summaryrefslogtreecommitdiff
path: root/shell/ash.c
diff options
context:
space:
mode:
authorDenys Vlasenko2010-08-07 22:24:36 +0200
committerDenys Vlasenko2010-08-07 22:24:36 +0200
commit33bbb27e45c7c6a0fecb40b3a5aa36aef69825f9 (patch)
treeb1038e6280788218428409acf45158bf0013c5d0 /shell/ash.c
parent58a15cd9d2765e9b9bca6b71ad9713bcc3784821 (diff)
downloadbusybox-33bbb27e45c7c6a0fecb40b3a5aa36aef69825f9.zip
busybox-33bbb27e45c7c6a0fecb40b3a5aa36aef69825f9.tar.gz
ash: fix another bit of var_bash4 bug
But it _still_ doesn't pass! quoted case is a tough nut to crack function old new delta redirect 1281 1286 +5 subevalvar 1141 1142 +1 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/ash.c')
-rw-r--r--shell/ash.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 6befe0f..4fbae24 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -6234,7 +6234,7 @@ parse_sub_pattern(char *arg, int varflags)
unsigned char c;
//char *org_arg = arg;
- //bb_error_msg("arg:'%s'", arg);
+ //bb_error_msg("arg:'%s' varflags:%x", arg, varflags);
idx = arg;
while (1) {
c = *arg;
@@ -6248,9 +6248,20 @@ parse_sub_pattern(char *arg, int varflags)
}
}
*idx++ = c;
- if (!(varflags & VSQUOTE) && c == '\\' && arg[1] == '\\')
- arg++; /* skip both \\, not just first one */
arg++;
+ /*
+ * Example: v='ab\c'; echo ${v/\\b/_\\_\z_}
+ * The result is a_\_z_c (not a\_\_z_c)!
+ *
+ * Enable debug prints in this function and you'll see:
+ * ash: arg:'\\b/_\\_z_' varflags:d
+ * ash: pattern:'\\b' repl:'_\_z_'
+ * That is, \\b is interpreted as \\b, but \\_ as \_!
+ * IOW: search pattern and replace string treat backslashes
+ * differently! That is the reason why we check repl below:
+ */
+ if (c == '\\' && *arg == '\\' && repl && !(varflags & VSQUOTE))
+ arg++; /* skip both '\', not just first one */
}
*idx = c; /* NUL */
//bb_error_msg("pattern:'%s' repl:'%s'", org_arg, repl);