parser: Only accept single-digit parameter expansion outside of braces
diff mbox series

Message ID 20190527053937.s3dmtzec4zo6gpcg@gondor.apana.org.au
State Under Review
Delegated to: Herbert Xu
Headers show
Series
  • parser: Only accept single-digit parameter expansion outside of braces
Related show

Commit Message

Herbert Xu May 27, 2019, 5:39 a.m. UTC
On Thu, Apr 25, 2019 at 01:39:52AM +0000, Michael Orlitzky wrote:
> The POSIX spec says,
> 
>   The parameter name or symbol can be enclosed in braces, which are
>   optional except for positional parameters with more than one digit or
>   when parameter is a name and is followed by a character that could be
>   interpreted as part of the name.
> 
> However, dash seems to diverge from that behavior when we get to $10:
> 
>   $ cat test.sh
>   echo $10
> 
>   $ dash ./test.sh one two three four five six seven eight nine ten
>   ten
> 
>   $ bash ./test.sh one two three four five six seven eight nine ten
>   one0

This patch should fix the problem.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Comments

Michael Orlitzky May 27, 2019, 1:52 p.m. UTC | #1
On 5/27/19 1:39 AM, Herbert Xu wrote:
> On Thu, Apr 25, 2019 at 01:39:52AM +0000, Michael Orlitzky wrote:
>>
>> However, dash seems to diverge from that behavior when we get to $10:
>>
>>   ...
> 
> This patch should fix the problem.
> 

Seems to work, thanks!

Patch
diff mbox series

diff --git a/src/parser.c b/src/parser.c
index 1f9e8ec..2f14bf3 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1268,7 +1268,7 @@  varname:
 			do {
 				STPUTC(c, out);
 				c = pgetc_eatbnl();
-			} while (is_digit(c));
+			} while (!subtype && is_digit(c));
 		} else if (c != '}') {
 			int cc = c;