ash: fix handling of single-quoted strings in pattern substitution

function                                             old     new   delta
subevalvar                                          1576    1588     +12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
master
Denys Vlasenko 2024-02-26 16:26:15 +01:00
parent f873c63085
commit c5a1be25ba
5 changed files with 29 additions and 0 deletions

View File

@ -7073,6 +7073,11 @@ subevalvar(char *start, char *str, int strloc,
repl = NULL;
break;
}
/* Skip over quoted 'str'. Example: ${var/'/'} - second / is not a separator */
if ((unsigned char)*repl == CTLQUOTEMARK) {
while ((unsigned char)*++repl != CTLQUOTEMARK)
continue;
}
if (*repl == '/') {
*repl = '\0';
break;

View File

@ -0,0 +1,4 @@
axxb
axxb
axxb
axxb

View File

@ -0,0 +1,8 @@
v="x/x"
# The second / is quoted, should not be treated as separator
echo a${v/'/'}b
# The second / is escaped, should not be treated as separator
echo a${v/\/}b
echo "a${v/'/'}b"
echo "a${v/\/}b"

View File

@ -0,0 +1,4 @@
axxb
axxb
axxb
axxb

View File

@ -0,0 +1,8 @@
v="x/x"
# The second / is quoted, should not be treated as separator
echo a${v/'/'}b
# The second / is escaped, should not be treated as separator
echo a${v/\/}b
echo "a${v/'/'}b"
echo "a${v/\/}b"