diff options
-rw-r--r-- | shell/ash.c | 28 | ||||
-rw-r--r-- | shell/ash_test/ash-vars/param_expand_len.right | 3 | ||||
-rwxr-xr-x | shell/ash_test/ash-vars/param_expand_len.tests | 7 | ||||
-rw-r--r-- | shell/hush_test/hush-vars/param_expand_len.right | 3 | ||||
-rwxr-xr-x | shell/hush_test/hush-vars/param_expand_len.tests | 7 |
5 files changed, 38 insertions, 10 deletions
diff --git a/shell/ash.c b/shell/ash.c index b404449d0..2cebfe2c0 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -11728,16 +11728,9 @@ parsesub: { | |||
11728 | subtype = VSNORMAL; | 11728 | subtype = VSNORMAL; |
11729 | if (c == '{') { | 11729 | if (c == '{') { |
11730 | c = pgetc_eatbnl(); | 11730 | c = pgetc_eatbnl(); |
11731 | if (c == '#') { | 11731 | subtype = 0; |
11732 | c = pgetc_eatbnl(); | ||
11733 | if (c == '}') | ||
11734 | c = '#'; /* ${#} - same as $# */ | ||
11735 | else | ||
11736 | subtype = VSLENGTH; /* ${#VAR} */ | ||
11737 | } else { | ||
11738 | subtype = 0; | ||
11739 | } | ||
11740 | } | 11732 | } |
11733 | varname: | ||
11741 | if (c <= 255 /* not PEOA or PEOF */ && is_name(c)) { | 11734 | if (c <= 255 /* not PEOA or PEOF */ && is_name(c)) { |
11742 | /* $[{[#]]NAME[}] */ | 11735 | /* $[{[#]]NAME[}] */ |
11743 | do { | 11736 | do { |
@@ -11752,8 +11745,23 @@ parsesub: { | |||
11752 | } while (isdigit(c)); | 11745 | } while (isdigit(c)); |
11753 | } else if (is_special(c)) { | 11746 | } else if (is_special(c)) { |
11754 | /* $[{[#]]<specialchar>[}] */ | 11747 | /* $[{[#]]<specialchar>[}] */ |
11755 | USTPUTC(c, out); | 11748 | int cc = c; |
11749 | |||
11756 | c = pgetc_eatbnl(); | 11750 | c = pgetc_eatbnl(); |
11751 | if (!subtype && cc == '#') { | ||
11752 | subtype = VSLENGTH; | ||
11753 | if (c == '_' || isalnum(c)) | ||
11754 | goto varname; | ||
11755 | cc = c; | ||
11756 | c = pgetc_eatbnl(); | ||
11757 | if (cc == '}' || c != '}') { | ||
11758 | pungetc(); | ||
11759 | subtype = 0; | ||
11760 | c = cc; | ||
11761 | cc = '#'; | ||
11762 | } | ||
11763 | } | ||
11764 | USTPUTC(cc, out); | ||
11757 | } else { | 11765 | } else { |
11758 | goto badsub; | 11766 | goto badsub; |
11759 | } | 11767 | } |
diff --git a/shell/ash_test/ash-vars/param_expand_len.right b/shell/ash_test/ash-vars/param_expand_len.right index 96e8cb59b..48d01d2fe 100644 --- a/shell/ash_test/ash-vars/param_expand_len.right +++ b/shell/ash_test/ash-vars/param_expand_len.right | |||
@@ -7,3 +7,6 @@ Make sure len parsing doesnt break arg count | |||
7 | Testing len op | 7 | Testing len op |
8 | 4 3 2 1 0 0 | 8 | 4 3 2 1 0 0 |
9 | 0 3 0 | 9 | 0 3 0 |
10 | Nothing: | ||
11 | Nothing: | ||
12 | One:1 | ||
diff --git a/shell/ash_test/ash-vars/param_expand_len.tests b/shell/ash_test/ash-vars/param_expand_len.tests index fe20a45e9..369c8d456 100755 --- a/shell/ash_test/ash-vars/param_expand_len.tests +++ b/shell/ash_test/ash-vars/param_expand_len.tests | |||
@@ -15,3 +15,10 @@ unset e | |||
15 | f=abc | 15 | f=abc |
16 | g= | 16 | g= |
17 | echo ${#e} ${#f} ${#g} | 17 | echo ${#e} ${#f} ${#g} |
18 | |||
19 | set -- a | ||
20 | # This must be interpreted as: $# ("1"), then remove trailing "1". | ||
21 | # IOW: empty result. | ||
22 | echo Nothing:${##1} | ||
23 | echo Nothing:${#%1} | ||
24 | echo One:${##x} | ||
diff --git a/shell/hush_test/hush-vars/param_expand_len.right b/shell/hush_test/hush-vars/param_expand_len.right index 96e8cb59b..48d01d2fe 100644 --- a/shell/hush_test/hush-vars/param_expand_len.right +++ b/shell/hush_test/hush-vars/param_expand_len.right | |||
@@ -7,3 +7,6 @@ Make sure len parsing doesnt break arg count | |||
7 | Testing len op | 7 | Testing len op |
8 | 4 3 2 1 0 0 | 8 | 4 3 2 1 0 0 |
9 | 0 3 0 | 9 | 0 3 0 |
10 | Nothing: | ||
11 | Nothing: | ||
12 | One:1 | ||
diff --git a/shell/hush_test/hush-vars/param_expand_len.tests b/shell/hush_test/hush-vars/param_expand_len.tests index fe20a45e9..369c8d456 100755 --- a/shell/hush_test/hush-vars/param_expand_len.tests +++ b/shell/hush_test/hush-vars/param_expand_len.tests | |||
@@ -15,3 +15,10 @@ unset e | |||
15 | f=abc | 15 | f=abc |
16 | g= | 16 | g= |
17 | echo ${#e} ${#f} ${#g} | 17 | echo ${#e} ${#f} ${#g} |
18 | |||
19 | set -- a | ||
20 | # This must be interpreted as: $# ("1"), then remove trailing "1". | ||
21 | # IOW: empty result. | ||
22 | echo Nothing:${##1} | ||
23 | echo Nothing:${#%1} | ||
24 | echo One:${##x} | ||