diff options
author | dana <dana@dana.is> | 2025-04-13 17:15:53 -0500 |
---|---|---|
committer | dana <dana@dana.is> | 2025-04-19 18:47:00 -0500 |
commit | 494fcd1799d4d2d236d3183de12b0c99ceb83b1c (patch) | |
tree | 447370bbd20acc6c1fe36be3d7a9ccdead3c63ff | |
parent | bacc78ec3f9d75ff242d0592b2f44484e1198801 (diff) | |
download | zsh-494fcd1799d4d2d236d3183de12b0c99ceb83b1c.tar.gz zsh-494fcd1799d4d2d236d3183de12b0c99ceb83b1c.zip |
53482: zparseopts -G: always add options with optional args to array with =
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | Src/Modules/zutil.c | 6 | ||||
-rw-r--r-- | Test/V12zparseopts.ztst | 4 |
3 files changed, 11 insertions, 5 deletions
@@ -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() 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 |