aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c10
-rw-r--r--shell/ash_test/ash-vars/var_bash_pattern_starting_with_slash.right2
-rwxr-xr-xshell/ash_test/ash-vars/var_bash_pattern_starting_with_slash.tests3
-rw-r--r--shell/hush.c9
-rw-r--r--shell/hush_test/hush-vars/var_bash_pattern_starting_with_slash.right2
-rwxr-xr-xshell/hush_test/hush-vars/var_bash_pattern_starting_with_slash.tests3
6 files changed, 28 insertions, 1 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 03fbbee53..5c431c9ff 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -6854,8 +6854,15 @@ subevalvar(char *p, char *varname, int strloc, int subtype,
if (subtype == VSREPLACE || subtype == VSREPLACEALL) {
/* Find '/' and replace with NUL */
repl = p;
+ /* 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 (*repl == '/')
+ repl++;
for (;;) {
- /* Handle escaped slashes, e.g. "${v/\//_}" (they are CTLESC'ed by this point) */
if (*repl == '\0') {
repl = NULL;
break;
@@ -6864,6 +6871,7 @@ subevalvar(char *p, char *varname, int strloc, int subtype,
*repl = '\0';
break;
}
+ /* Handle escaped slashes, e.g. "${v/\//_}" (they are CTLESC'ed by this point) */
if ((unsigned char)*repl == CTLESC && repl[1])
repl++;
repl++;
diff --git a/shell/ash_test/ash-vars/var_bash_pattern_starting_with_slash.right b/shell/ash_test/ash-vars/var_bash_pattern_starting_with_slash.right
new file mode 100644
index 000000000..439dca578
--- /dev/null
+++ b/shell/ash_test/ash-vars/var_bash_pattern_starting_with_slash.right
@@ -0,0 +1,2 @@
+-dev-ram
+/dev-am
diff --git a/shell/ash_test/ash-vars/var_bash_pattern_starting_with_slash.tests b/shell/ash_test/ash-vars/var_bash_pattern_starting_with_slash.tests
new file mode 100755
index 000000000..b83fb8eeb
--- /dev/null
+++ b/shell/ash_test/ash-vars/var_bash_pattern_starting_with_slash.tests
@@ -0,0 +1,3 @@
+v=/dev/ram
+echo ${v////-}
+echo ${v///r/-}
diff --git a/shell/hush.c b/shell/hush.c
index 6852b5f79..3407711cd 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;
diff --git a/shell/hush_test/hush-vars/var_bash_pattern_starting_with_slash.right b/shell/hush_test/hush-vars/var_bash_pattern_starting_with_slash.right
new file mode 100644
index 000000000..439dca578
--- /dev/null
+++ b/shell/hush_test/hush-vars/var_bash_pattern_starting_with_slash.right
@@ -0,0 +1,2 @@
+-dev-ram
+/dev-am
diff --git a/shell/hush_test/hush-vars/var_bash_pattern_starting_with_slash.tests b/shell/hush_test/hush-vars/var_bash_pattern_starting_with_slash.tests
new file mode 100755
index 000000000..b83fb8eeb
--- /dev/null
+++ b/shell/hush_test/hush-vars/var_bash_pattern_starting_with_slash.tests
@@ -0,0 +1,3 @@
+v=/dev/ram
+echo ${v////-}
+echo ${v///r/-}