special-case another bizarre POSIX corner case
after david korn agreed to change ksh93 to match
This commit is contained in:
		
							
								
								
									
										18
									
								
								check.t
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								check.t
									
									
									
									
									
								
							| @@ -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: 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: 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 $ | # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ | ||||||
| @@ -1392,6 +1392,22 @@ expected-stderr-pattern: | |||||||
| 	/bad substitution/ | 	/bad substitution/ | ||||||
| expected-exit: 1 | 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 | name: eglob-bad-1 | ||||||
| description: | description: | ||||||
| 	Check that globbing isn't done when glob has syntax error | 	Check that globbing isn't done when glob has syntax error | ||||||
|   | |||||||
							
								
								
									
										21
									
								
								lex.c
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								lex.c
									
									
									
									
									
								
							| @@ -22,7 +22,7 @@ | |||||||
|  |  | ||||||
| #include "sh.h" | #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 |  * states while lexing word | ||||||
| @@ -1634,13 +1634,12 @@ promptlen(const char *cp) | |||||||
| static char * | static char * | ||||||
| get_brace_var(XString *wsp, char *wp) | get_brace_var(XString *wsp, char *wp) | ||||||
| { | { | ||||||
|  | 	char c; | ||||||
| 	enum parse_state { | 	enum parse_state { | ||||||
| 		PS_INITIAL, PS_SAW_HASH, PS_IDENT, | 		PS_INITIAL, PS_SAW_HASH, PS_IDENT, | ||||||
| 		PS_NUMBER, PS_VAR1 | 		PS_NUMBER, PS_VAR1 | ||||||
| 	} state; | 	} state = PS_INITIAL; | ||||||
| 	char c; |  | ||||||
|  |  | ||||||
| 	state = PS_INITIAL; |  | ||||||
| 	while (/* CONSTCOND */ 1) { | 	while (/* CONSTCOND */ 1) { | ||||||
| 		c = getsc(); | 		c = getsc(); | ||||||
| 		/* State machine to figure out where the variable part ends. */ | 		/* State machine to figure out where the variable part ends. */ | ||||||
| @@ -1656,7 +1655,19 @@ get_brace_var(XString *wsp, char *wp) | |||||||
| 				state = PS_IDENT; | 				state = PS_IDENT; | ||||||
| 			else if (ksh_isdigit(c)) | 			else if (ksh_isdigit(c)) | ||||||
| 				state = PS_NUMBER; | 				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; | 				state = PS_VAR1; | ||||||
| 			else | 			else | ||||||
| 				goto out; | 				goto out; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user