summaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
authorDenys Vlasenko2018-08-04 22:25:28 +0200
committerDenys Vlasenko2018-08-04 22:25:28 +0200
commitc2aa218f23a4e952746ebef7bb86668c6255471c (patch)
tree6a2884b85c52a31ad9b69e7bd2cde5d688fa139e /shell/hush.c
parent2005d3ff3661220f11e8ff1911b24051b3669566 (diff)
downloadbusybox-c2aa218f23a4e952746ebef7bb86668c6255471c.zip
busybox-c2aa218f23a4e952746ebef7bb86668c6255471c.tar.gz
ash,hush: properly handle ${v//pattern/repl} if pattern starts with /
Closes 2695 function old new delta parse_dollar 762 790 +28 subevalvar 1258 1267 +9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 37/0) Total: 37 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/hush.c')
-rw-r--r--shell/hush.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 6852b5f..3407711 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -4930,6 +4930,15 @@ static int parse_dollar(o_string *as_string,
end_ch = '}' * 0x100 + '/';
}
o_addchr(dest, ch);
+ /* The pattern can't be empty.
+ * IOW: if the first char after "${v//" is a slash,
+ * it does not terminate the pattern - it's the first char of the pattern:
+ * v=/dev/ram; echo ${v////-} prints -dev-ram (pattern is "/")
+ * v=/dev/ram; echo ${v///r/-} prints /dev-am (pattern is "/r")
+ */
+ if (i_peek(input) == '/') {
+ o_addchr(dest, i_getch(input));
+ }
again:
if (!BB_MMU)
pos = dest->length;