zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] zed fails with setopt nounset unless option -x is given
@ 2022-05-20 14:06 Risto Laitinen
  2022-05-20 14:17 ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Risto Laitinen @ 2022-05-20 14:06 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 95 bytes --]

% zsh-5.9 -f
% autoload zed
% setopt nounset
% zed a.txt
zed:21: opts[-x]: parameter not set
%

[-- Attachment #2: 0001-zed-nounset.txt --]
[-- Type: text/plain, Size: 369 bytes --]

--- Functions/Misc/zed.orig	2022-05-20 16:45:13.709144850 +0300
+++ Functions/Misc/zed	2022-05-20 16:45:56.313326625 +0300
@@ -18,7 +18,7 @@
 fun=$+opts[-f]
 hist=$+opts[-h]
 bind=$+opts[-b]
-if [[ $opts[-x] == <-> ]]; then
+if [[ ${opts[-x]-} == <-> ]]; then
   expand=(-x $opts[-x])
 elif (( $+opts[-x] )); then
   print -r "Integer expected after -x: $opts[-x]" >&2

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] zed fails with setopt nounset unless option -x is given
  2022-05-20 14:06 [PATCH] zed fails with setopt nounset unless option -x is given Risto Laitinen
@ 2022-05-20 14:17 ` Peter Stephenson
  2022-05-20 14:39   ` Bart Schaefer
                     ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Peter Stephenson @ 2022-05-20 14:17 UTC (permalink / raw)
  To: Risto Laitinen, zsh-workers

> On 20 May 2022 at 15:06 Risto Laitinen <risto.laitinen@gmail.com> wrote:
> % zsh-5.9 -f
> % autoload zed
> % setopt nounset
> % zed a.txt
> zed:21: opts[-x]: parameter not set
> %

Looks straightforward.

zed runs as "emulate zsh"; it seems reasonable that nounset isn't
treated as an emulation option, given it's more for debugging, but
that means there could well be a lot more of these lurking.

pws

diff --git a/Functions/Misc/zed b/Functions/Misc/zed
index 7d0d590db..582a15d25 100644
--- a/Functions/Misc/zed
+++ b/Functions/Misc/zed
@@ -18,7 +18,7 @@ zparseopts -D -A opts f h b x:
 fun=$+opts[-f]
 hist=$+opts[-h]
 bind=$+opts[-b]
-if [[ $opts[-x] == <-> ]]; then
+if [[ $+opts[-x] == 1 && $opts[-x] == <-> ]]; then
   expand=(-x $opts[-x])
 elif (( $+opts[-x] )); then
   print -r "Integer expected after -x: $opts[-x]" >&2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] zed fails with setopt nounset unless option -x is given
  2022-05-20 14:17 ` Peter Stephenson
@ 2022-05-20 14:39   ` Bart Schaefer
  2022-05-20 15:00   ` Bart Schaefer
  2022-05-25  9:48   ` Peter Stephenson
  2 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2022-05-20 14:39 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Risto Laitinen, Zsh hackers list

On Fri, May 20, 2022 at 7:18 AM Peter Stephenson
<p.w.stephenson@ntlworld.com> wrote:
>
> zed runs as "emulate zsh"; it seems reasonable that nounset isn't
> treated as an emulation option, given it's more for debugging

Hmm.  That's a tough one.  "... only those options likely to cause
portability problems in scripts and functions are altered."  NOUNSET
certainly seems to fall into that category, because:

> that means there could well be a lot more of these lurking.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] zed fails with setopt nounset unless option -x is given
  2022-05-20 14:17 ` Peter Stephenson
  2022-05-20 14:39   ` Bart Schaefer
@ 2022-05-20 15:00   ` Bart Schaefer
  2022-05-25  9:48   ` Peter Stephenson
  2 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2022-05-20 15:00 UTC (permalink / raw)
  To: Zsh hackers list

On Fri, May 20, 2022 at 7:18 AM Peter Stephenson
<p.w.stephenson@ntlworld.com> wrote:
>
> Looks straightforward.
>
> +if [[ $+opts[-x] == 1 && $opts[-x] == <-> ]]; then

This actually points out a potential issue with nounset in general:
There's no way to pre-declare an associative array key (or even a
normal array element) to prevent this from happening, the way one can
use typeset to declare a scalar.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] zed fails with setopt nounset unless option -x is given
  2022-05-20 14:17 ` Peter Stephenson
  2022-05-20 14:39   ` Bart Schaefer
  2022-05-20 15:00   ` Bart Schaefer
@ 2022-05-25  9:48   ` Peter Stephenson
  2 siblings, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 2022-05-25  9:48 UTC (permalink / raw)
  To: Risto Laitinen, zsh-workers


> On 20 May 2022 at 15:17 Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> 
> 
> > On 20 May 2022 at 15:06 Risto Laitinen <risto.laitinen@gmail.com> wrote:
> > % zsh-5.9 -f
> > % autoload zed
> > % setopt nounset
> > % zed a.txt
> > zed:21: opts[-x]: parameter not set
> > %
> 
> Looks straightforward.

This is a little better (it doesn't take account of the point Bart
noted).  The option handler will return on a bad argument, so actually
the internal handling is now redundant.

pws

diff --git a/Functions/Misc/zed b/Functions/Misc/zed
index 7d0d590db..bb075512c 100644
--- a/Functions/Misc/zed
+++ b/Functions/Misc/zed
@@ -14,15 +14,17 @@ local var opts zed_file_name
 integer TMOUT=0 okargs=1 fun hist bind
 local -a expand
 
-zparseopts -D -A opts f h b x:
+zparseopts -D -A opts f h b x: || return 1
 fun=$+opts[-f]
 hist=$+opts[-h]
 bind=$+opts[-b]
-if [[ $opts[-x] == <-> ]]; then
-  expand=(-x $opts[-x])
-elif (( $+opts[-x] )); then
-  print -r "Integer expected after -x: $opts[-x]" >&2
-  return 1
+if (( $+opts[-x] )); then
+  if [[ $opts[-x] == <-> ]]; then
+    expand=(-x $opts[-x])
+  else
+    print -r "Integer expected after -x: $opts[-x]" >&2
+    return 1
+  fi
 fi
 
 [[ $0 = fned ]] && fun=1


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-05-25  9:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-20 14:06 [PATCH] zed fails with setopt nounset unless option -x is given Risto Laitinen
2022-05-20 14:17 ` Peter Stephenson
2022-05-20 14:39   ` Bart Schaefer
2022-05-20 15:00   ` Bart Schaefer
2022-05-25  9:48   ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).