zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] More rigorous subscript checking in named references
@ 2023-02-12 20:16 Bart Schaefer
  2023-02-12 23:13 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Bart Schaefer @ 2023-02-12 20:16 UTC (permalink / raw)
  To: Zsh hackers list

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

The first 7 named ref patches have been pushed, so there ends the
increasingly inaccurately named patch trilogy, at least in the subject
lines.

This covers the case Oliver called out, of extra stuff following a
valid subscript.

[-- Attachment #2: nameref-8-subscripts.txt --]
[-- Type: text/plain, Size: 1064 bytes --]

diff --git a/Src/params.c b/Src/params.c
index 4910d65fe..f61374b87 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -6281,7 +6281,16 @@ valid_refname(char *val)
     if (*t != 0) {
 	if (*t == '[') {
 	    tokenize(t = dupstring(t+1));
-	    t = parse_subscript(t, 0, ']');
+	    while ((t = parse_subscript(t, 0, ']')) && *t++ == Outbrack) {
+		if (*t == Inbrack)
+		    ++t;
+		else
+		    break;
+	    }
+	    if (t && *t) {
+		/* zwarn("%s: stuff after subscript: %s", val, t); */
+		t = NULL;
+	    }
 	} else if (t[1] || !(*t == '!' || *t == '?' ||
 			     *t == '$' || *t == '-' ||
 			     *t == '0' || *t == '_')) {
diff --git a/Test/K01nameref.ztst b/Test/K01nameref.ztst
index 61c2b006a..d2abdd391 100644
--- a/Test/K01nameref.ztst
+++ b/Test/K01nameref.ztst
@@ -350,9 +350,9 @@ F:ksh93 does not implement this either
 >typeset -A hash=( [y]=HIT )
 
  unset -n ptr1
- typeset -n ptr1='not good'
+ typeset -n ptr1='not[2]good'
 1:invalid nameref
-*?*invalid variable name: not good
+*?*invalid variable name: not\[2\]good
 
  unset -n ptr1
  unset hash

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

* Re: [PATCH] More rigorous subscript checking in named references
  2023-02-12 20:16 [PATCH] More rigorous subscript checking in named references Bart Schaefer
@ 2023-02-12 23:13 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2023-02-12 23:13 UTC (permalink / raw)
  To: Zsh hackers list

On Sun, Feb 12, 2023 at 12:16 PM Bart Schaefer
<schaefer@brasslantern.com> wrote:
>
> This covers the case Oliver called out, of extra stuff following a
> valid subscript.

On Sun, Feb 12, 2023 at 2:54 PM Oliver Kiddle <opk@zsh.org> wrote:
>
> That still leaves the oddities with a second subscript:
>
>   typeset -n ref='arr[2][1]'
>   arr=( one two three )
>   echo $ref
>   echo ${ref}
>   ref=Z
>   typeset -p arr
>
> Only case where the second subscript works is when ref is in braces.

Hmm ... I think that has something to do with this:

% arr[2]=two
% arr[2][1]=Z
zsh: no matches found: arr[2][1]=Z

That is, there's a level deeper than where namerefs operate that
doesn't parse past the first subscript.  I'm not sure how hard to work
on that (or if we even want the latter case to work).

I'll keep a note of it, though.


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

end of thread, other threads:[~2023-02-12 23:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-12 20:16 [PATCH] More rigorous subscript checking in named references Bart Schaefer
2023-02-12 23:13 ` Bart Schaefer

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).