mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
src/cmd/ksh93/bltins/whence.c: - The previous commit that fixed 'unset -f' in virtual subshells left one bug. The type builtin (or 'whence -v') could still find the unset function in virtual subshells: $ foo() { echo foo; } $ (unset -f foo; type foo) foo is an undefined function To fix this bug, avoid detecting functions in the whence builtin unless they have the NV_FUNCTION flag. src/cmd/ksh93/tests/subshell.sh: - Add a regression test for using 'type' on a function unset inside of a virtual subshell.
This commit is contained in:
parent
07faf38425
commit
24b7fcb771
2 changed files with 11 additions and 1 deletions
|
@ -192,7 +192,7 @@ static int whence(Shell_t *shp,char **argv, register int flags)
|
||||||
}
|
}
|
||||||
/* built-ins and functions next */
|
/* built-ins and functions next */
|
||||||
bltins:
|
bltins:
|
||||||
if(!(flags&F_FLAG) && (np = nv_bfsearch(name, shp->fun_tree, &nq, ¬used)) && !is_abuiltin(np))
|
if(!(flags&F_FLAG) && (np = nv_bfsearch(name, shp->fun_tree, &nq, ¬used)) && is_afunction(np))
|
||||||
{
|
{
|
||||||
if(flags&Q_FLAG)
|
if(flags&Q_FLAG)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -699,6 +699,16 @@ got=$( f() { echo WRONG; }; ( unset -f f; PATH=/dev/null f 2>&1 ) )
|
||||||
[[ $got == $exp ]] || err_exit 'unset -f fails in sub-subshell on function set in subshell' \
|
[[ $got == $exp ]] || err_exit 'unset -f fails in sub-subshell on function set in subshell' \
|
||||||
"(expected match of $(printf %q "$exp"), got $(printf %q "$got"))"
|
"(expected match of $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||||
|
|
||||||
|
# Functions unset in a subshell shouldn't be detected by type (whence -v)
|
||||||
|
# https://github.com/ksh93/ksh/pull/287
|
||||||
|
notafunc() {
|
||||||
|
echo 'Failure'
|
||||||
|
}
|
||||||
|
exp=Success
|
||||||
|
got=$(unset -f notafunc; type notafunc 2>/dev/null || echo Success)
|
||||||
|
[[ $got == "$exp" ]] || err_exit "type/whence -v finds function in virtual subshell after it's unset with 'unset -f'" \
|
||||||
|
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||||
|
|
||||||
# ======
|
# ======
|
||||||
# Unsetting or redefining aliases within subshells
|
# Unsetting or redefining aliases within subshells
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue