When parsing an invalid parameter expansion (eg. ${} or ${foo@bar}) do not
issue a syntax error immediately but save the information that it is erroneous for later when the parameter expansion is actually done. This means eg. "false && ${}" will not generate an error which seems to be required by POSIX. Include the invalid parameter expansion in the error message (sometimes abbreviated with ... because recovering it would require a lot of code). PR: 105078 Submitted by: emaste
This commit is contained in:
parent
67be76c039
commit
62addaefc9
@ -763,6 +763,11 @@ evalvar(char *p, int flag)
|
||||
goto record;
|
||||
break;
|
||||
|
||||
case VSERROR:
|
||||
c = p - var - 1;
|
||||
error("${%.*s%s}: Bad substitution", c, var,
|
||||
(c > 0 && *p != CTLENDVAR) ? "..." : "");
|
||||
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
@ -1228,12 +1228,17 @@ parsesub: {
|
||||
c = pgetc();
|
||||
}
|
||||
} else {
|
||||
if (! is_special(c))
|
||||
badsub: synerror("Bad substitution");
|
||||
USTPUTC(c, out);
|
||||
c = pgetc();
|
||||
if (! is_special(c)) {
|
||||
subtype = VSERROR;
|
||||
if (c == '}')
|
||||
pungetc();
|
||||
else
|
||||
USTPUTC(c, out);
|
||||
} else {
|
||||
USTPUTC(c, out);
|
||||
c = pgetc();
|
||||
}
|
||||
}
|
||||
STPUTC('=', out);
|
||||
flags = 0;
|
||||
if (subtype == 0) {
|
||||
switch (c) {
|
||||
@ -1243,9 +1248,13 @@ badsub: synerror("Bad substitution");
|
||||
/*FALLTHROUGH*/
|
||||
default:
|
||||
p = strchr(types, c);
|
||||
if (p == NULL)
|
||||
goto badsub;
|
||||
subtype = p - types + VSNORMAL;
|
||||
if (p == NULL) {
|
||||
if (flags == VSNUL)
|
||||
STPUTC(':', out);
|
||||
STPUTC(c, out);
|
||||
subtype = VSERROR;
|
||||
} else
|
||||
subtype = p - types + VSNORMAL;
|
||||
break;
|
||||
case '%':
|
||||
case '#':
|
||||
@ -1261,9 +1270,10 @@ badsub: synerror("Bad substitution");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else if (subtype != VSERROR) {
|
||||
pungetc();
|
||||
}
|
||||
STPUTC('=', out);
|
||||
if (subtype != VSLENGTH && (dblquote || arinest))
|
||||
flags |= VSQUOTE;
|
||||
*(stackblock() + typeloc) = subtype | flags;
|
||||
|
@ -60,6 +60,7 @@
|
||||
#define VSTRIMRIGHT 0x8 /* ${var%pattern} */
|
||||
#define VSTRIMRIGHTMAX 0x9 /* ${var%%pattern} */
|
||||
#define VSLENGTH 0xa /* ${#var} */
|
||||
#define VSERROR 0xb /* Syntax error, issue when expanded */
|
||||
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user