diff options
author | Ron Yorston <rmy@pobox.com> | 2015-05-18 09:53:26 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-05-18 09:53:26 +0200 |
commit | 3df47f9cbbb7f16608cbc642026625cdf7f06aa9 (patch) | |
tree | a2bc999e17bcf10c29bceeb1403cbc7ef658aa84 /shell | |
parent | eb6b48ba743d510ad9e6f9c3a8b3899d1eb9b5f3 (diff) | |
download | busybox-w32-3df47f9cbbb7f16608cbc642026625cdf7f06aa9.tar.gz busybox-w32-3df47f9cbbb7f16608cbc642026625cdf7f06aa9.tar.bz2 busybox-w32-3df47f9cbbb7f16608cbc642026625cdf7f06aa9.zip |
ash: do not expand tilde in parameter expansion within quotes
Test case:
unset a
echo "${a:-~root}"
Old result:
/root
New result:
~root
Based on commit 170f44d from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu
function old new delta
evalvar 598 604 +6
parse_command 1440 1443 +3
localcmd 325 327 +2
readtoken1 3199 3200 +1
argstr 1180 1164 -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/1 up/down: 12/-16) Total: -4 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
3 files changed, 6 insertions, 5 deletions
diff --git a/shell/ash.c b/shell/ash.c index 4c43f1f30..d87166c4f 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -5529,7 +5529,7 @@ ash_arith(const char *s) | |||
5529 | #define EXP_RECORD 0x20 /* need to record arguments for ifs breakup */ | 5529 | #define EXP_RECORD 0x20 /* need to record arguments for ifs breakup */ |
5530 | #define EXP_VARTILDE2 0x40 /* expand tildes after colons only */ | 5530 | #define EXP_VARTILDE2 0x40 /* expand tildes after colons only */ |
5531 | #define EXP_WORD 0x80 /* expand word in parameter expansion */ | 5531 | #define EXP_WORD 0x80 /* expand word in parameter expansion */ |
5532 | #define EXP_QWORD 0x100 /* expand word in quoted parameter expansion */ | 5532 | #define EXP_QUOTED 0x100 /* expand word in double quotes */ |
5533 | /* | 5533 | /* |
5534 | * rmescape() flags | 5534 | * rmescape() flags |
5535 | */ | 5535 | */ |
@@ -6054,7 +6054,7 @@ argstr(char *p, int flags, struct strlist *var_str_list) | |||
6054 | }; | 6054 | }; |
6055 | const char *reject = spclchars; | 6055 | const char *reject = spclchars; |
6056 | int quotes = flags & QUOTES_ESC; | 6056 | int quotes = flags & QUOTES_ESC; |
6057 | int breakall = flags & EXP_WORD; | 6057 | int breakall = (flags & (EXP_WORD | EXP_QUOTED)) == EXP_WORD; |
6058 | int inquotes; | 6058 | int inquotes; |
6059 | size_t length; | 6059 | size_t length; |
6060 | int startloc; | 6060 | int startloc; |
@@ -6072,8 +6072,6 @@ argstr(char *p, int flags, struct strlist *var_str_list) | |||
6072 | flags &= ~EXP_TILDE; | 6072 | flags &= ~EXP_TILDE; |
6073 | tilde: | 6073 | tilde: |
6074 | q = p; | 6074 | q = p; |
6075 | if ((unsigned char)*q == CTLESC && (flags & EXP_QWORD)) | ||
6076 | q++; | ||
6077 | if (*q == '~') | 6075 | if (*q == '~') |
6078 | p = exptilde(p, q, flags); | 6076 | p = exptilde(p, q, flags); |
6079 | } | 6077 | } |
@@ -6790,7 +6788,7 @@ evalvar(char *p, int flags, struct strlist *var_str_list) | |||
6790 | if (varlen < 0) { | 6788 | if (varlen < 0) { |
6791 | argstr( | 6789 | argstr( |
6792 | p, | 6790 | p, |
6793 | flags | (quoted ? EXP_TILDE|EXP_QWORD : EXP_TILDE|EXP_WORD), | 6791 | flags | EXP_TILDE | EXP_WORD | (quoted ? EXP_QUOTED : 0), |
6794 | var_str_list | 6792 | var_str_list |
6795 | ); | 6793 | ); |
6796 | goto end; | 6794 | goto end; |
diff --git a/shell/ash_test/ash-vars/var-do-not-expand-tilde-in-parameter-expansion-in-quotes.right b/shell/ash_test/ash-vars/var-do-not-expand-tilde-in-parameter-expansion-in-quotes.right new file mode 100644 index 000000000..4b9b4f038 --- /dev/null +++ b/shell/ash_test/ash-vars/var-do-not-expand-tilde-in-parameter-expansion-in-quotes.right | |||
@@ -0,0 +1 @@ | |||
~root | |||
diff --git a/shell/ash_test/ash-vars/var-do-not-expand-tilde-in-parameter-expansion-in-quotes.tests b/shell/ash_test/ash-vars/var-do-not-expand-tilde-in-parameter-expansion-in-quotes.tests new file mode 100755 index 000000000..d8eb8fc1b --- /dev/null +++ b/shell/ash_test/ash-vars/var-do-not-expand-tilde-in-parameter-expansion-in-quotes.tests | |||
@@ -0,0 +1,2 @@ | |||
1 | unset a | ||
2 | echo "${a:-~root}" | ||