diff mbox series

parser: Fix regression on ${#10} expansion

Message ID 20210208034127.GA31149@gondor.apana.org.au (mailing list archive)
State Not Applicable
Delegated to: Herbert Xu
Headers show
Series parser: Fix regression on ${#10} expansion | expand

Commit Message

Herbert Xu Feb. 8, 2021, 3:41 a.m. UTC
Thanks for the patch!

---8<---
Vladimir N. Oleynik <dzo@simtreas.ru> wrote:
> 
> dash have bug for ${#10} and etc: ignores 0... in name (without errors :)
> 
> $ foo() { echo "length 10-th arg '${10}' is ${#10}"; }
> $ foo a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11
> length 10-th arg 'a10' is 2
> 
> But need:
> length 10-th arg 'a10' is 3
> 
> Micro patch attached
>
> --- parser.c~   2021-02-04 00:51:34.000000000 +0400
> +++ parser.c    2021-02-05 12:42:43.616635640 +0400
> @@ -1274,7 +1274,7 @@
>                        do {
>                                STPUTC(c, out);
>                                c = pgetc_eatbnl();
> -                       } while (!subtype && is_digit(c));
> +                       } while ((!subtype || subtype == VSLENGTH) && is_digit(c));
>                } else if (c != '}') {
>                        int cc = c;

I would rather test against VSNORMAL.

Fixes: 7710a926b321 ("parser: Only accept single-digit parameter...")
Reported-by: Vladimir N. Oleynik <dzo@simtreas.ru>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Comments

Vladimir N. Oleynik Feb. 10, 2021, 3:30 p.m. UTC | #1
Hello, Herbert.

Herbert Xu wrote:

> Thanks for the patch!

> I would rather test against VSNORMAL.

Yes, its true for support indirection ${!var}
and realized by me :)

But I do not show this patch in
https://git.kernel.org/pub/scm/utils/dash/dash.git/
Its ok?


--w
vodz
Herbert Xu Feb. 11, 2021, 4:55 a.m. UTC | #2
On Wed, Feb 10, 2021 at 07:30:17PM +0400, Vladimir N. Oleynik wrote:
>
> But I do not show this patch in
> https://git.kernel.org/pub/scm/utils/dash/dash.git/
> Its ok?

It's still in the review process:

https://patchwork.kernel.org/project/dash/list/

Thanks,
diff mbox series

Patch

diff --git a/src/parser.c b/src/parser.c
index 3c80d17..834d2e3 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1252,7 +1252,7 @@  varname:
 			do {
 				STPUTC(c, out);
 				c = pgetc_eatbnl();
-			} while (!subtype && is_digit(c));
+			} while (subtype != VSNORMAL && is_digit(c));
 		} else if (c != '}') {
 			int cc = c;