1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-06-11 07:08:07 +02:00

53482: zparseopts -G: always add options with optional args to array with =

This commit is contained in:
dana 2025-04-13 17:15:53 -05:00
parent bacc78ec3f
commit 494fcd1799
3 changed files with 11 additions and 5 deletions

View file

@ -1,3 +1,9 @@
2025-04-19 dana <dana@dana.is>
* 53482: Src/Modules/zutil.c,
Src/Modules/Test/V12zparseopts.ztst: with `zparseopts -G`,
always add options options with optional args to array with =
2025-04-15 Bart Schaefer <schaefer@zsh.org>
* 53454: Src/hist.c: fix interrupt handling in savehistfile()

View file

@ -1662,15 +1662,15 @@ add_opt_val(Zoptdesc d, char *arg)
v->str = NULL;
if (d->arr)
d->arr->num += (arg ? 2 : 1);
} else if (arg) {
} else if (arg || d->flags & ZOF_GNUL) {
/* 3 here is '-' + '=' + NUL */
char *s = (char *) zhalloc(strlen(d->name) + strlen(arg) + 3);
char *s = (char *) zhalloc(strlen(d->name) + strlen(arg ? arg : "") + 3);
*s = '-';
strcpy(s + 1, d->name);
if (d->flags & ZOF_GNUL)
strcat(s, "=");
strcat(s, arg);
strcat(s, arg ? arg : "");
v->str = s;
if (d->arr)
d->arr->num += 1;

View file

@ -247,7 +247,7 @@
0:zparseopts -G, separate parameters
>ret: 0, optv: --foo bar, argv: 1 2 3
>ret: 0, optv: --foo=bar, argv: 1 2 3
>ret: 0, optv: --foo, argv: bar 1 2 3
>ret: 0, optv: --foo=, argv: bar 1 2 3
for spec in -foo: -foo:- -foo::; do
() {
@ -340,4 +340,4 @@
?(anon):zparseopts:2: bad option: -f
>ret: 1, gopt: -G, optv: , argv: -foobar 1 2 3
>ret: 0, gopt: -G, optv: -foo=bar, argv: 1 2 3
>ret: 0, gopt: -G, optv: -foo, argv: bar 1 2 3
>ret: 0, gopt: -G, optv: -foo=, argv: bar 1 2 3