zsh-workers
 help / color / mirror / code / Atom feed
* SourceForge bug id 104052 - case study.
@ 2000-08-15 15:36 Andrej Borsenkow
  2000-08-18  9:12 ` Question " Andrej Borsenkow
  0 siblings, 1 reply; 2+ messages in thread
From: Andrej Borsenkow @ 2000-08-15 15:36 UTC (permalink / raw)
  To: ZSH workers mailing list

May be, it is well known already.

There are at least three different cases covered by this bug:

Case 1.

bor@itsrm2% typeset -A foo
bor@itsrm2% foo[\]]=bar
zsh: not an identifier: foo[\]]

Case 2.

bor@itsrm2% print $foo[\]]
]
bor@itsrm2% print ${foo[\]]}
zsh: bad substitution

Case 3.

bor@itsrm2% print $foo[(I)[^]]]
bar] <== that I do not understand at all!
bor@itsrm2% print ${(kv)foo}
a bar abc baz

Case 1 is caused by the fact, that setsparam() gets unmetafied parameter name.
Ironically, in this case everything is correctly parsed, `]' is properly
quoted, but distinction between `]' and `\]' is lost when parameter is
unmetafied. setsparam() calls isident(), that just checks for balanced `[' and
`]' and barfs (it never checks what is really inside the brackets).

Case 2 comes from the fact, that paramsubst() and getindex() treat both quoted
and unquoted brackets the same. The reason is (as I suspect) parameter
substitution in double-quotes - "$foo[bar]". When it is parsed by
dquote_parse(), it adds just plain ']' and not Outbrack; so, when it finally
reaches paramsubst() it may encounter both values. When inside of parens, Zsh
just warns about missing closing one (because it finds end of substitution too
early).

Case 3 the problem seems to be getarg(). It blindly skips over balanced
brackets that is of course wrong in this case.

Case 1 is basically independent of other two. Unfortunately, to solve it we
need to either remove call to isident() in setsparam() or pass metafied
parameter name to setsparam() and make isident() smart enough.

Case 2 - lexer should return different token for "]" as for \], e.g. Qoutbrack
like Qstring. And, of course, all uses of ']'/Outbrack should be checked ...
but note, that in this case

$foo[\]]

will be valid, but

"$foo[\]]"

not. By definition, you cannot quote inside of double quotes. Even

$foo["]"]

will be invalid in this case (a bit unexpected), unless code can be smart
enough to notice, that initial Inbrack was not quoted.

Case 3 - we may try to change (getarg(), around line 916 in Src/params.c)

	else if (c == ']' || c == Outbrack)

into something like

	else if ((c == ']' || c == Outbrack) &&
                t[-1] != '^' && t[-1] != '!' && t[-2] != '[' && t[-2] !=
Inbrack)

but this highly ambiguous case remains

$foo[(I)$bar[^]]

-andrej


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

* Question RE: SourceForge bug id 104052 - case study.
  2000-08-15 15:36 SourceForge bug id 104052 - case study Andrej Borsenkow
@ 2000-08-18  9:12 ` Andrej Borsenkow
  0 siblings, 0 replies; 2+ messages in thread
From: Andrej Borsenkow @ 2000-08-18  9:12 UTC (permalink / raw)
  To: ZSH workers mailing list

>
> Case 2.
>
> bor@itsrm2% print $foo[\]]
> ]
> bor@itsrm2% print ${foo[\]]}
> zsh: bad substitution
>
...
>
> Case 2 comes from the fact, that paramsubst() and getindex() treat
> both quoted
> and unquoted brackets the same. The reason is (as I suspect) parameter
> substitution in double-quotes - "$foo[bar]". When it is parsed by
> dquote_parse(), it adds just plain ']' and not Outbrack; so, when it finally
> reaches paramsubst() it may encounter both values. When inside of
> parens, Zsh
> just warns about missing closing one (because it finds end of
> substitution too
> early).
>
...
>
> Case 2 - lexer should return different token for "]" as for \],
> e.g. Qoutbrack
> like Qstring. And, of course, all uses of ']'/Outbrack should be checked ...
> but note, that in this case
>
> $foo[\]]
>
> will be valid, but
>
> "$foo[\]]"
>
> not. By definition, you cannot quote inside of double quotes. Even
>
> $foo["]"]
>
> will be invalid in this case (a bit unexpected), unless code can be smart
> enough to notice, that initial Inbrack was not quoted.
>


This may work if we allow backslash to quote `]' inside of doublequotes.
Because POSIX explcitly forbids it, it should be turned off at least in sh
mode; so something like new option SH_STRICT_QUOTING is needed (or, probably,
even POSIX_STRICT_QUOTING would be better name). That will make $foo[\]] and
"$foo[\]]" both work and produce the same result.

Neither sh nor ksh have this problem, as they do not have associated arrays; I
could not compile new ksh so I do not know how it behaves.

If there is no much con, I'll give it a try.

-andrej



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

end of thread, other threads:[~2000-08-18  9:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-08-15 15:36 SourceForge bug id 104052 - case study Andrej Borsenkow
2000-08-18  9:12 ` Question " Andrej Borsenkow

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