Skip to content

Commit 9e2e6ca

Browse files
committed
lex.c: restore lexd.nested_tilde flag & handling (re: c40851a)
Removing that flag was a mistake, because it serves another purpose: if it is set, the 'continue' on line 700 is executed, avoiding the 'goto epat' online 704 or the state table change to ST_NORM on line 706 when we're within ~(...) within ${...}.
1 parent 218102c commit 9e2e6ca

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/cmd/ksh93/include/shlex.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct _shlex_pvt_lexdata_
5050
char dolparen_arithexp; /* set while comsub() is lexing an arithmetic expansion */
5151
char nest;
5252
char docword;
53+
char nested_tilde;
5354
char *docend;
5455
char inlexskip; /* set when sh_lex() is called from sh_lexskip() */
5556
char warn;

src/cmd/ksh93/include/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <ast_release.h>
1919
#include "git.h"
2020

21-
#define SH_RELEASE_DATE "2025-06-08" /* must be in this format for $((.sh.version)) */
21+
#define SH_RELEASE_DATE "2025-06-09" /* must be in this format for $((.sh.version)) */
2222
/*
2323
* This comment keeps SH_RELEASE_DATE a few lines away from SH_RELEASE_SVER to avoid
2424
* merge conflicts when cherry-picking dev branch commits onto a release branch.

src/cmd/ksh93/sh/lex.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,10 @@ int sh_lex(Lex_t* lp)
660660
if(c=='~' && mode==ST_NESTED)
661661
{
662662
if(endchar(lp)==RBRACE)
663+
{
664+
lp->lexd.nested_tilde++;
663665
goto tilde;
666+
}
664667
continue;
665668
}
666669
/* FALLTHROUGH */
@@ -683,9 +686,19 @@ int sh_lex(Lex_t* lp)
683686
n = fcgetc();
684687
if(n>0)
685688
{
686-
if(c=='~' && n==LPAREN && lp->lex.incase)
687-
lp->lex.incase = TEST_RE;
689+
if(c=='~' && n==LPAREN)
690+
{
691+
if(lp->lexd.nested_tilde)
692+
lp->lexd.nested_tilde++;
693+
else if(lp->lex.incase)
694+
lp->lex.incase = TEST_RE;
695+
}
688696
fcseek(-LEN);
697+
if(lp->lexd.nested_tilde)
698+
{
699+
lp->lexd.nested_tilde--;
700+
continue;
701+
}
689702
}
690703
if(n==LPAREN)
691704
goto epat;
@@ -1063,6 +1076,8 @@ int sh_lex(Lex_t* lp)
10631076
fcseek(-LEN);
10641077
n = RPAREN;
10651078
}
1079+
if(c==RBRACE)
1080+
lp->lexd.nested_tilde = 0;
10661081
if(c==';' && n!=';')
10671082
continue;
10681083
if(mode==ST_QNEST)

0 commit comments

Comments
 (0)