diff --git a/NEWS b/NEWS index 6db435a3e..5d5c289c5 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,7 @@ Any uppercase BUG_* names are modernish shell bug IDs. - Fixed: when the DEBUG trap was redefined in a subshell, the DEBUG trap in the parent environment was corrupted or the shell crashed. + When a redirection was used in a DEBUG trap action, the trap was disabled. 2021-01-22: diff --git a/src/cmd/ksh93/tests/basic.sh b/src/cmd/ksh93/tests/basic.sh index 1540693db..db2ac777b 100755 --- a/src/cmd/ksh93/tests/basic.sh +++ b/src/cmd/ksh93/tests/basic.sh @@ -745,6 +745,20 @@ got=$(eval 'x=`for i in test; do case $i in test) true;; esac; done`' 2>&1) \ || err_exit "case in a for loop inside a \`comsub\` caused syntax error (got $(printf %q "$got"))" # ====== +# Redirecting disabled the DEBUG trap +# https://github.com/ksh93/ksh/issues/155 (#1) +exp=$'LINENO: 4\nfoo\nLINENO: 5\nLINENO: 6\nbar\nLINENO: 7\nbaz' +got=$({ "$SHELL" -c ' + PATH=/dev/null + trap "echo LINENO: \$LINENO >&1" DEBUG # 3 + echo foo # 4 + var=$(echo) # 5 + echo bar # 6 + echo baz # 7 +'; } 2>&1) +((!(e = $?))) && [[ $got == "$exp" ]] || err_exit 'Redirection in DEBUG trap corrupts the trap' \ + "(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$got"))" + # The DEBUG trap crashed when re-trapping inside a subshell # https://github.com/ksh93/ksh/issues/155 (#2) exp=$'trap -- \': main\' EXIT\ntrap -- \': main\' ERR\ntrap -- \': main\' KEYBD\ntrap -- \': main\' DEBUG' @@ -760,7 +774,6 @@ got=$({ "$SHELL" -c ' ((!(e = $?))) && [[ $got == "$exp" ]] || err_exit 'Pseudosignal trap failed when re-trapping in subshell' \ "(got status $e$( ((e>128)) && print -n / && kill -l "$e"), $(printf %q "$got"))" -# ====== # The DEBUG trap had side effects on the exit status # https://github.com/ksh93/ksh/issues/155 (#4) trap ':' DEBUG