1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-04-30 05:45:16 +02:00

51887: namespaces recognized in math, incorrect usages rejected.

This commit is contained in:
Bart Schaefer 2023-06-22 13:36:40 -07:00
parent e7a8dbb16c
commit 4345eed1fe
4 changed files with 86 additions and 6 deletions

View File

@ -1,5 +1,8 @@
2023-06-22 Bart Schaefer <schaefer@zsh.org>
* 51887: Src/math.c, Src/params.c, Test/K02parameter.ztst:
namespaces recognized in math, incorrect usages rejected.
* Marlon Richert: 51860: Completion/Base/Completer/_prefix,
Test/Y01completion.ztst, Test/comptest: simplify suffix handling
in _prefix to remove longstanding and less accurate hack; tests.

View File

@ -641,7 +641,9 @@ zzlex(void)
return MINUSEQ;
}
if (unary) {
if (idigit(*ptr) || *ptr == '.') {
if (idigit(*ptr) ||
(*ptr == '.' &&
(idigit(ptr[1]) || !itype_end(ptr, INAMESPC, 0)))) {
int ctype = lexconstant();
if (ctype == NUM)
{
@ -835,7 +837,9 @@ zzlex(void)
case Dnull:
break;
default:
if (idigit(*--ptr) || *ptr == '.')
if (idigit(*--ptr) ||
(*ptr == '.' &&
(idigit(ptr[1]) || !itype_end(ptr, INAMESPC, 0))))
return lexconstant();
if (*ptr == '#') {
if (*++ptr == '\\' || *ptr == '#') {
@ -857,7 +861,7 @@ zzlex(void)
}
cct = 1;
}
if ((ie = itype_end(ptr, IIDENT, 0)) != ptr) {
if ((ie = itype_end(ptr, INAMESPC, 0)) != ptr) {
int func = 0;
char *p;

View File

@ -1226,6 +1226,26 @@ isident(char *s)
if (!*s) /* empty string is definitely not valid */
return 0;
/* This partly duplicates code in itype_end(), but we need to
* distinguish the leading namespace at this point to check the
* correctness of the identifier that follows
*/
if (*s == '.') {
if (idigit(s[1]))
return 0; /* Namespace must not start with a digit */
/* Reject identifiers beginning with a digit in namespaces.
* Move this out below this block to also reject v.1x form.
*/
if ((ss = itype_end(s + (*s == '.'), IIDENT, 0))) {
if (*ss == '.') {
if (!ss[1])
return 0;
if (idigit(ss[1]))
s = ss + 1;
}
}
}
if (idigit(*s)) {
/* If the first character is `s' is a digit, then all must be */
for (ss = ++s; *ss; ss++)
@ -2148,7 +2168,12 @@ fetchvalue(Value v, char **pptr, int bracks, int flags)
pm = (Param) paramtab->getnode2(paramtab, *t == '0' ? "0" : t);
else
pm = (Param) paramtab->getnode(paramtab, *t == '0' ? "0" : t);
if (sav)
if (!pm && *t == '.' && !isident(t)) {
/* badly formed namespace reference */
if (sav)
*s = sav;
return NULL;
} else if (sav)
*s = sav;
*pptr = s;
if (!pm || ((pm->node.flags & PM_UNSET) &&

View File

@ -100,7 +100,55 @@ F:Braces are required
>.k02.array
>characters
k.=empty
k.2=test
print ${k.2}
print ${k.} ${k.2}
0:Parse without leading dot (future proofing)
>test
>empty test
.k=OK
print ${.k}
0:Bare namespace is usable (ksh compatibility)
>OK
.k.=empty
1:Namespace must precede an identifier, assignment
?(eval):1: not an identifier: .k.
typeset .k.=empty
1:Namespace must precede an identifier, typeset
?(eval):typeset:1: not valid in this context: .k.
print ${.k.}
1:Namespace must precede an identifier, reference
?(eval):1: bad substitution
.2.b=not
1:Namespace identifier must not begin with a digit, assignment
?(eval):1: not an identifier: .2.b
typeset .2.b=not
1:Namespace identifier must not begin with a digit, typeset
?(eval):typeset:1: not valid in this context: .2.b
print ${.2.b}
1:Namespace identifier must not begin with a digit, reference
?(eval):1: bad substitution
.not.2b=question
1:Identifier starting with a digit must be all digits, assignment
?(eval):1: not an identifier: .not.2b
typeset .not.2b=question
1:Identifier starting with a digit must be all digits, typeset
?(eval):typeset:1: not valid in this context: .not.2b
print ${.not.2b}
1:Identifier starting with a digit must be all digits, reference
?(eval):1: bad substitution
integer .var.d=0
float .var.f=.2
print $((.var.x = ++.var.d - -.var.f))
0:Namespaces in math context
>1.2