From 494fcd1799d4d2d236d3183de12b0c99ceb83b1c Mon Sep 17 00:00:00 2001 From: dana Date: Sun, 13 Apr 2025 17:15:53 -0500 Subject: 53482: zparseopts -G: always add options with optional args to array with = --- ChangeLog | 6 ++++++ Src/Modules/zutil.c | 6 +++--- Test/V12zparseopts.ztst | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4b4913252..39b488e14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2025-04-19 dana + + * 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 * 53454: Src/hist.c: fix interrupt handling in savehistfile() diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c index 9b2721a09..ef99303d2 100644 --- a/Src/Modules/zutil.c +++ b/Src/Modules/zutil.c @@ -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; diff --git a/Test/V12zparseopts.ztst b/Test/V12zparseopts.ztst index a2743ea0e..e465d0e0c 100644 --- a/Test/V12zparseopts.ztst +++ b/Test/V12zparseopts.ztst @@ -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 -- cgit v1.2.3