From 8f14514661ea9e15fc71019de6bef02a4dd9b627 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Sat, 28 May 2022 00:02:46 +0100 Subject: [PATCH] set --default: properly restore ksh IFS behaviour (re: 9e2a8c69) Reproducer: $ (IFS=$'\t\t'; val=$'\tone\t\ttwo\t'; set --posix; \ set -- $val; echo $#; set --noposix; set -- $val; echo $#) 2 4 <== OK $ (IFS=$'\t\t'; val=$'\tone\t\ttwo\t'; set --posix; \ set -- $val; echo $#; set --default; set -- $val; echo $#) 2 2 <== bug The output of the seconnd command line should be like the first. When POSIX mode is turned off using 'set --noposix' (or 'set +o posix'), sh.ifstable is invalidated as it needs to be repopulated on the next field split to restore ksh-specific special handling of a repeated $IFS whitespace character as non-whitespace. However, when 'set --default' is used, this does not happen, which is a bug. src/cmd/ksh93/sh/args.c: sh_argopts(): - While processing --default, when turning off SH_POSIX, call sh_invalidate_ifs() to invalidate sh.ifstable. --- NEWS | 6 ++++++ src/cmd/ksh93/include/version.h | 2 +- src/cmd/ksh93/sh/args.c | 6 ++++++ src/cmd/ksh93/tests/posix.sh | 3 +++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index c0fa3248d..16b751465 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,12 @@ For full details, see the git log at: https://github.com/ksh93/ksh/tree/1.0 Any uppercase BUG_* names are modernish shell bug IDs. +2022-05-27: + +- Fixed a bug introduced on 2022-03-05 where 'set --default', while turning + off the --posix option, did not re-enable the special handling of a repeated + $IFS whitespace character as non-whitespace. + 2022-05-25: - Fixed a bug introduced on 2021-02-20 that caused incorrect output for diff --git a/src/cmd/ksh93/include/version.h b/src/cmd/ksh93/include/version.h index d4af15fd8..e2bd413c8 100644 --- a/src/cmd/ksh93/include/version.h +++ b/src/cmd/ksh93/include/version.h @@ -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-beta.2" /* semantic version number: https://semver.org */ -#define SH_RELEASE_DATE "2022-05-25" /* must be in this format for $((.sh.version)) */ +#define SH_RELEASE_DATE "2022-05-27" /* must be in this format for $((.sh.version)) */ #define SH_RELEASE_CPYR "(c) 2020-2022 Contributors to ksh " SH_RELEASE_FORK /* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */ diff --git a/src/cmd/ksh93/sh/args.c b/src/cmd/ksh93/sh/args.c index 5e8488553..36701ec96 100644 --- a/src/cmd/ksh93/sh/args.c +++ b/src/cmd/ksh93/sh/args.c @@ -170,8 +170,14 @@ int sh_argopts(int argc,register char *argv[]) { register const Shtable_t *tp; for(tp=shtab_options; o = tp->sh_number; tp++) + { if(!(o&SH_COMMANDLINE) && (o&=0xff)!=SH_RESTRICTED && is_option(&newflags,o)) + { off_option(&newflags,o); + if(o==SH_POSIX) + sh_invalidate_ifs(); + } + } } defaultflag++; continue; diff --git a/src/cmd/ksh93/tests/posix.sh b/src/cmd/ksh93/tests/posix.sh index 91702deeb..8f98907ea 100644 --- a/src/cmd/ksh93/tests/posix.sh +++ b/src/cmd/ksh93/tests/posix.sh @@ -113,6 +113,9 @@ got=$(set --noposix; set $val; echo "$#") exp=5 [[ $got == "$exp" ]] || err_exit "repeated IFS whitespace char (noposix): incorrect number of fields" \ "(expected $(printf %q "$exp"), got $(printf %q "$got"))" +got=$(set --default; set $val; echo "$#") +[[ $got == "$exp" ]] || err_exit "repeated IFS whitespace char (default): incorrect number of fields" \ + "(expected $(printf %q "$exp"), got $(printf %q "$got"))" IFS=$' \t\n' # default # causes file descriptors > 2 to be left open when invoking another program;