Skip to content

Commit 2315f66

Browse files
committed
Add regress test for fixed BUG_KUNSETIFS (re: 6f0e008, 7b994b6)
Modernish is no longer detecting BUG_KUNSETIFS, as I've just discovered. Always nice when bugs spontaneously vanish... A 'git reset HEAD~1'/recompile/retest loop reveals this bug was fixed by 6f0e008, as later modified by 7b994b6. So, let's make sure it stays fixed. src/cmd/ksh93/tests/variables.sh: - Add a couple of regression tests for BUG_KUNSETIFS presence, detection and known workaround, based on the same in modernish. Ref.: https://github.com/modernish/modernish/blob/3ddcbd13/lib/modernish/cap/BUG_KUNSETIFS.t https://github.com/modernish/modernish/blob/3ddcbd13/lib/modernish/tst/isset.t#L204-L222
1 parent 43c09c2 commit 2315f66

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ Any uppercase BUG_* names are modernish shell bug IDs.
180180
etc. to lose their effect after being unset in a subshell. For example:
181181
(unset PATH; PATH=/dev/null; ls); : wrongly ran 'ls'
182182
(unset LC_ALL; LC_ALL=badlocale); : failed to print a diagnostic
183+
This also fixes BUG_KUNSETIFS: unsetting IFS in a subshell failed if IFS
184+
was set to the empty value in the parent shell.
183185

184186
- Fix crashes on some systems, including at least a crash in 'print -v' on
185187
macOS, by eliminating an invalid/undefined use of memccpy() on overlapping

TODO

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ https://github.com/modernish/modernish/tree/0.16/lib/modernish/cap/
7171
are erroneously interpreted as wildcards when quoted "$*" is used as the
7272
glob pattern.
7373

74-
- BUG_KUNSETIFS: ksh93: Can't unset IFS under very specific circumstances.
75-
unset -v IFS is a known POSIX shell idiom to activate default field
76-
splitting. With this bug, the unset builtin silently fails to unset IFS
77-
(i.e. fails to activate field splitting) if we're executing an eval or a
78-
trap and a number of specific conditions are met.
79-
8074
- BUG_LOOPRET2: If a 'return' command is given without a status argument
8175
within the set of conditional commands in a 'while' or 'until' loop (i.e.,
8276
between 'while'/'until' and 'do'), the exit status passed down from the

src/cmd/ksh93/tests/variables.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ fi
268268
for i in : % + / 3b '**' '***' '@@' '{' '[' '}' !! '*a' '$foo'
269269
do (eval : \${"$i"} 2> /dev/null) && err_exit "\${$i} not an syntax error"
270270
done
271+
272+
# ___ begin: IFS tests ___
273+
271274
unset IFS
272275
( IFS=' ' ; read -r a b c <<-!
273276
x y z
@@ -418,6 +421,29 @@ do
418421
;;
419422
esac
420423
done
424+
425+
# BUG_KUNSETIFS: Unsetting IFS fails to activate default default field splitting if two conditions are met:
426+
IFS='' # condition 1: no split in main shell
427+
: ${foo-} # at least one expansion is also needed to trigger this
428+
( # condition 2: subshell (non-forked)
429+
unset IFS
430+
v="one two three"
431+
set -- $v
432+
let "$# == 3" # without bug, should be 3
433+
) || err_exit 'IFS fails to be unset in subshell (BUG_KUNSETIFS)'
434+
435+
# Test known BUG_KUNSETIFS workaround (assign to IFS before unset)
436+
IFS= v=
437+
: ${v:=a$'\n'bc$'\t'def\ gh}
438+
case $(unset IFS; set -- $v; print $#) in
439+
4 | 1) # test if the workaround works whether we've got the bug or not
440+
v=$(IFS=foobar; unset IFS; set -- $v; print $#)
441+
[[ $v == 4 ]] || err_exit "BUG_KUNSETIFS workaround fails (expected 4, got $v)" ;;
442+
*) err_exit 'BUG_KUNSETIFS detection failed'
443+
esac
444+
445+
# ^^^ end: IFS tests ^^^
446+
# restore default split:
421447
unset IFS
422448

423449
if [[ $( (print ${12345:?}) 2>&1) != *12345* ]]

0 commit comments

Comments
 (0)