special-case another bizarre POSIX corner case

after david korn agreed to change ksh93 to match
This commit is contained in:
tg 2011-03-26 16:11:43 +00:00
parent b1d97ea44e
commit 84f7055f8f
2 changed files with 33 additions and 6 deletions

18
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.433 2011/03/26 15:32:35 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.434 2011/03/26 16:11:41 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -1392,6 +1392,22 @@ expected-stderr-pattern:
/bad substitution/
expected-exit: 1
---
name: expand-trim-1
description:
Check corner case of trim expansion vs. $# vs. ${#var}
stdin:
set 1 2 3 4 5 6 7 8 9 10 11
echo ${#} # value of $#
echo ${##} # length of $#
echo ${##1} # $# trimmed 1
set 1 2 3 4 5 6 7 8 9 10 11 12
echo ${##1}
expected-stdout:
11
2
1
2
---
name: eglob-bad-1
description:
Check that globbing isn't done when glob has syntax error

21
lex.c
View File

@ -22,7 +22,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.143 2011/03/26 15:32:37 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.144 2011/03/26 16:11:43 tg Exp $");
/*
* states while lexing word
@ -1634,13 +1634,12 @@ promptlen(const char *cp)
static char *
get_brace_var(XString *wsp, char *wp)
{
char c;
enum parse_state {
PS_INITIAL, PS_SAW_HASH, PS_IDENT,
PS_NUMBER, PS_VAR1
} state;
char c;
} state = PS_INITIAL;
state = PS_INITIAL;
while (/* CONSTCOND */ 1) {
c = getsc();
/* State machine to figure out where the variable part ends. */
@ -1656,7 +1655,19 @@ get_brace_var(XString *wsp, char *wp)
state = PS_IDENT;
else if (ksh_isdigit(c))
state = PS_NUMBER;
else if (ctype(c, C_VAR1))
else if (c == '#') {
if (state == PS_SAW_HASH) {
char c2;
c2 = getsc();
ungetsc(c2);
if (c2 != '}') {
ungetsc(c);
goto out;
}
}
state = PS_VAR1;
} else if (ctype(c, C_VAR1))
state = PS_VAR1;
else
goto out;