Skip to content

Commit

Permalink
Fix remaining bug in ${var:-'{}'} (re: d087b03)
Browse files Browse the repository at this point in the history
The following problems remained:

$ var=x; echo ${var:-'{}'}
x}
$ var=; echo ${var:+'{}'}
}

src/cmd/ksh93/sh/macro.c: varsub():
- Use the new ST_MOD1 state table to skip over ${var-'foo'}, etc.
  instead of ST_QUOTE. In ST_MOD1 the ' is categorised as S_LIT
  which causes the single quotes to be skipped over correctly.
  See d087b03 for more info.

src/cmd/ksh93/tests/quoting2.sh:
- Add tests for this remaining bug.
- Make the new test xtrace-proof.

Resolves: #290 (again)
  • Loading branch information
McDutchie committed May 3, 2021
1 parent 1aec9b0 commit f31e368
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ For full details, see the git log at: https://github.com/ksh93/ksh

Any uppercase BUG_* names are modernish shell bug IDs.

2021-05-03:

- Completed the 2021-04-30 fix for ${var<OP>'{}'} where <OP> is '-', '+',
':-' or ':+' by fixing a bug that caused an extra '}' to be output.

2021-04-30:

- The emacs 'ESC .' (M-.) and vi '_' commands now take shell quoting into
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
#define SH_RELEASE_SVER "1.0.0-alpha" /* semantic version number: https://semver.org */
#define SH_RELEASE_DATE "2021-04-30" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_DATE "2021-05-03" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_CPYR "(c) 2020-2021 Contributors to ksh " SH_RELEASE_FORK

/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/sh/macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ static int varsub(Mac_t *mp)
}
else
{
sh_lexskip(lp, RBRACE, 0, sh_lexstates[ST_BRACE][c]==S_MOD1 ? ST_QUOTE : ST_NESTED);
sh_lexskip(lp, RBRACE, 0, sh_lexstates[ST_BRACE][c]==S_MOD1 ? ST_MOD1 : ST_NESTED);
stkseek(stkp,offset);
}
argp=stkptr(stkp,offset);
Expand Down
20 changes: 18 additions & 2 deletions src/cmd/ksh93/tests/quoting2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,30 @@ actual=$(printf %q $'1\x[11]1')
# https://github.com/ksh93/ksh/issues/290
var=dummy
exp='{}'
got=$(eval 'echo ${var:+'\''{}'\''}' 2>&1)
got=$(set +x; eval 'echo ${var:+'\''{}'\''}' 2>&1)
[[ $got == "$exp" ]] || err_exit "Single quotes misparsed in expansion operator string (1)" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
unset var
exp='}'
got=$(eval 'echo ${var:-'\''}'\''}' 2>&1)
got=$(set +x; eval 'echo ${var:-'\''}'\''}' 2>&1)
[[ $got == "$exp" ]] || err_exit "Single quotes misparsed in expansion operator string (2)" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
exp='x'
got=$(var=x; set +x; eval 'echo ${var:-'\''{}'\''}' 2>&1)
[[ $got == "$exp" ]] || err_exit "Single quotes misparsed in expansion operator string (3)" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
exp=''
got=$(var=; set +x; eval 'echo ${var:+'\''{}'\''}' 2>&1)
[[ $got == "$exp" ]] || err_exit "Single quotes misparsed in expansion operator string (4)" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
exp='{}'
got=$(unset var; set +x; eval 'echo ${var-'\''{}'\''}' 2>&1)
[[ $got == "$exp" ]] || err_exit "Single quotes misparsed in expansion operator string (5)" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
exp=''
got=$(unset var; set +x; eval 'echo ${var+'\''{}'\''}' 2>&1)
[[ $got == "$exp" ]] || err_exit "Single quotes misparsed in expansion operator string (6)" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"

# ======
exit $((Errors<125?Errors:125))

0 comments on commit f31e368

Please sign in to comment.