Bug 2695 - ash's ${var/pattern/repl} is buggy
Summary: ash's ${var/pattern/repl} is buggy
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Standard Compliance (show other bugs)
Version: 1.22.x
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
: 2281 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-10-11 00:12 UTC by Marco Clocchiatti
Modified: 2018-08-04 20:27 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marco Clocchiatti 2010-10-11 00:12:09 UTC
s939 ~ # chroot busybox bin/sh
/ # busybox|head -n1
BusyBox v1.15.3 (2010-09-20 13:10:56 CEST) multi-call binary
/ # find . -exec ls -l {} \;
drwxr-xr-x    2 0        0            2048 Oct 10 23:49 bin
-rwxr-xr-x    1 0        0         2062112 Sep 20 11:11 busybox
lrwxrwxrwx    1 0        0               7 Oct 10 23:49 sh -> busybox
-rwxr-xr-x    1 0        0         2062112 Sep 20 11:11 ./bin/busybox
lrwxrwxrwx    1 0        0               7 Oct 10 23:49 ./bin/sh -> busybox
/ # #example with pattern containing slashes:
/ # var="/dev/ram0"
/ # echo ${var////-}
/dev/ram0
/ # #example with pattern not containing slashes:
/ # var="|dev|ram0"
/ # echo ${var//|/-}
-dev-ram0
/ # exit
Comment 1 Denys Vlasenko 2010-10-30 02:54:48 UTC
*** Bug 2281 has been marked as a duplicate of this bug. ***
Comment 2 Denys Vlasenko 2010-10-30 02:55:02 UTC
From bug 2281
=============

There was a bug in expansion of star inside parameter in expressions like
${FOO//\\*/-star-}. In bash 2 and lower two backslashes were eaten for escaping
of star. Since bash 3 the bug is fixed. The fix introduced a small change of
the behavior (one backslash escapes second backslash). Also zsh already
migrated to the fixed behavior.

Busybox exactly follows (at least in version 1.13) the bash 2 behavior
considered as broken. It would be nice to migrate it to the fixed behavior.

Example:

FOO="a*b\\*c" ; echo ${FOO//\\*/-backslashstar-}

Bash 2, busybox:
a-backslashstar-b-\backslashstar-c

Bash 3, Bash 4, zsh:
a*b-backslashstar-

---------------------

Fixed in git. While at it, found and quashed two more bugs.
However, quoted version:

FOO="a*b\\*c"; echo "${FOO//\\*/-backslashstar-}"

is still broken, and is _hard_ to fix.

There is now a testcase for it:
Go to busybox/shell/ash_test in buld tree and run "run-all".
Examine ash-vars-var_bash4.tests.fail to see quoted expansion error.
Comment 3 Bastian Bittorf 2015-03-02 10:53:31 UTC
the testcase

{{{
# var='/dev/ram0'
# echo ${var////-}
/dev/ram0
# should output: '-dev-ram0'
}}}

is still not working. checked with git 1eafd4494706c21a87dc66e4e0afa8799b576cb5 from 2015-mar-23 and release v1.22.1 - it should also be added to 'shell/ash_test/ash-vars/'.

thanks for your work - Bastian Bittorf
Comment 4 Denys Vlasenko 2018-08-04 20:27:39 UTC
Fixed in git.