Skip to content

Commit a14d17c

Browse files
committed
Allow turning off brace expansion in comsubs (rhbz#1078698)
There was no check for the -B/braceexpand option before calling path_expand() to process brace expansion, making it impossible to turn off brace expansion within command substitutions. Normally the lexer flags brace expansion so that this code is not reached, but shell code within command substitutions is handled differently. Red Hat patches this by adding this check to the function itself: https://src.fedoraproject.org/rpms/ksh/blob/642af4d6/f/ksh-20140301-fikspand.patch But I think it's more logical to patch it at the point of decision. src/cmd/ksh93/sh/macro.c: endfield(): - Decide to call either path_generate() or path_expand() based on the state of the SH_BRACEEXPAND shell option. - Fix '#if SHOPT_BRACEPAT' preprocessor check that previously hardcoded this decision at compile time. src/cmd/ksh93/tests/options.sh: - Add tests.
1 parent c1d9eed commit a14d17c

4 files changed

Lines changed: 25 additions & 4 deletions

File tree

‎NEWS‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ For full details, see the git log at: https://github.com/ksh93/ksh
33

44
Any uppercase BUG_* names are modernish shell bug IDs.
55

6+
2020-09-24:
7+
8+
- An omission made it impossible to turn off brace expansion within command
9+
substitutions (`...`, $(...) or ${ ...; }) as the code for parsing these
10+
did not check the -B/braceexpand option. This check has now been added.
11+
612
2020-09-23:
713

814
- Fixed a crash that could occur when running a pipeline containing

‎src/cmd/ksh93/include/version.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
* David Korn <dgk@research.att.com> *
1818
* *
1919
***********************************************************************/
20-
#define SH_RELEASE "93u+m 2020-09-23"
20+
#define SH_RELEASE "93u+m 2020-09-24"

‎src/cmd/ksh93/sh/macro.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,10 +2489,11 @@ static void endfield(register Mac_t *mp,int split)
24892489
{
24902490
mp->shp->argaddr = 0;
24912491
#if SHOPT_BRACEPAT
2492-
count = path_generate(mp->shp,argp,mp->arghead);
2493-
#else
2494-
count = path_expand(mp->shp,argp->argval,mp->arghead);
2492+
if(sh_isoption(SH_BRACEEXPAND))
2493+
count = path_generate(mp->shp,argp,mp->arghead);
2494+
else
24952495
#endif /* SHOPT_BRACEPAT */
2496+
count = path_expand(mp->shp,argp->argval,mp->arghead);
24962497
if(count)
24972498
mp->fields += count;
24982499
else if(split) /* pattern is null string */

‎src/cmd/ksh93/tests/options.sh‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,5 +547,19 @@ print $'alias print=:\nprint foobar' > dotfile
547547
"$SHELL" -m -c '[[ -o monitor ]]' || err_exit 'option -m on command line does not work'
548548
"$SHELL" -o monitor -c '[[ -o monitor ]]' || err_exit 'option -o monitor on command line does not work'
549549

550+
# ======
551+
# Brace expansion could not be turned off in command substitutions (rhbz#1078698)
552+
set -B
553+
expect='test{1,2}'
554+
actual=$(set +B; echo `echo test{1,2}`)
555+
[[ $actual == "$expect" ]] || err_exit 'Brace expansion not turned off in `comsub`' \
556+
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
557+
actual=$(set +B; echo $(echo test{1,2}))
558+
[[ $actual == "$expect" ]] || err_exit 'Brace expansion not turned off in $(comsub)' \
559+
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
560+
actual=$(set +B; echo ${ echo test{1,2}; })
561+
[[ $actual == "$expect" ]] || err_exit 'Brace expansion not turned off in ${ comsub; }' \
562+
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
563+
550564
# ======
551565
exit $((Errors<125?Errors:125))

0 commit comments

Comments
 (0)