mirror of
https://github.com/zdharma-continuum/zinit.git
synced 2026-09-10 07:36:38 -04:00
fix: prevent "permission denied" errors from empty hook handlers (#729)
Co-authored-by: Philipp Schmitt <pschmitt@users.noreply.github.com>
This commit is contained in:
parent
c153788560
commit
2167408db2
64
tests/hook-handler.zunit
Executable file
64
tests/hook-handler.zunit
Executable file
|
|
@ -0,0 +1,64 @@
|
|||
#!/usr/bin/env zunit
|
||||
|
||||
# Tests for issue #728: Empty hook handlers cause "permission denied" errors
|
||||
# https://github.com/zdharma-continuum/zinit/issues/728
|
||||
|
||||
@setup {
|
||||
# Set up minimal zinit environment
|
||||
HOME="$zi_test_dir"
|
||||
typeset -gA ZINIT ZINIT_EXTS ZINIT_EXTS2 ICE
|
||||
ZINIT[BIN_DIR]="${PWD}"
|
||||
ZINIT[PLUGINS_DIR]="$zi_test_dir/plugins"
|
||||
ZINIT[SNIPPETS_DIR]="$zi_test_dir/snippets"
|
||||
ZINIT[HOME_DIR]="$zi_test_dir"
|
||||
|
||||
# Source zinit
|
||||
source "${PWD}/zinit.zsh"
|
||||
}
|
||||
|
||||
@test 'empty hook handler error is prevented by fix' {
|
||||
# This test verifies the fix for issue #728
|
||||
# Without the fix, empty hook handlers cause "permission denied:" errors
|
||||
|
||||
# Register extension with empty handler (the exact pattern that triggers the bug)
|
||||
ZINIT_EXTS["zinit hook:preinit-pre 10"]="10 z-annex-data: test-annex hook:preinit-pre '' '' ''"
|
||||
|
||||
# Test the hook processing logic directly
|
||||
# This simulates what happens in .zinit-load at line 1648-1652
|
||||
local output=""
|
||||
local error_code=0
|
||||
|
||||
# Get the hook keys (simulating the reply array)
|
||||
local -a test_keys
|
||||
test_keys=( "zinit hook:preinit-pre 10" )
|
||||
|
||||
# Process hooks
|
||||
for ___key in "${test_keys[@]}"; do
|
||||
local -a ___arr
|
||||
___arr=( "${(Q)${(z@)ZINIT_EXTS[$___key]:-$ZINIT_EXTS2[$___key]}[@]}" )
|
||||
|
||||
# With our fix, this checks if handler is non-empty before executing
|
||||
if [[ -n "${___arr[5]:-}" ]]; then
|
||||
output="would execute handler"
|
||||
else
|
||||
output="skipped empty handler"
|
||||
fi
|
||||
done
|
||||
|
||||
# Verify the fix prevented execution of empty handler
|
||||
assert "$output" same_as "skipped empty handler"
|
||||
}
|
||||
|
||||
@test 'direct test of empty command execution fails' {
|
||||
# This demonstrates the underlying issue reported in #728
|
||||
local empty_var=""
|
||||
|
||||
# Executing an empty variable causes "permission denied:"
|
||||
run zsh -c 'empty_var=""; "${empty_var}"'
|
||||
|
||||
# Verify it fails with permission denied
|
||||
assert $state equals 126 # 126 is the error code for permission denied
|
||||
assert "$output" contains "permission denied:"
|
||||
}
|
||||
|
||||
# vim:ft=zsh:sw=2:sts=2:et:foldmarker={,}:foldmethod=marker
|
||||
12
zinit.zsh
12
zinit.zsh
|
|
@ -1443,8 +1443,10 @@ builtin setopt noaliases
|
|||
)
|
||||
for key in "${reply[@]}"; do
|
||||
arr=( "${(Q)${(z@)ZINIT_EXTS[$key]:-$ZINIT_EXTS2[$key]}[@]}" )
|
||||
"${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" "${${key##(zinit|z-annex) hook:}%% <->}" load || \
|
||||
return $(( 10 - $? ))
|
||||
if [[ -n "${arr[5]:-}" ]]; then
|
||||
"${arr[5]}" snippet "$save_url" "$id_as" "$local_dir/$dirname" "${${key##(zinit|z-annex) hook:}%% <->}" load || \
|
||||
return $(( 10 - $? ))
|
||||
fi
|
||||
done
|
||||
|
||||
# Download or copy the file.
|
||||
|
|
@ -1647,8 +1649,10 @@ builtin setopt noaliases
|
|||
)
|
||||
for ___key in "${reply[@]}"; do
|
||||
___arr=( "${(Q)${(z@)ZINIT_EXTS[$___key]:-$ZINIT_EXTS2[$___key]}[@]}" )
|
||||
"${___arr[5]}" plugin "$___user" "$___plugin" "$___id_as" "$___pdir_orig" "${${___key##(zinit|z-annex) hook:}%% <->}" load || \
|
||||
return $(( 10 - $? ))
|
||||
if [[ -n "${___arr[5]:-}" ]]; then
|
||||
"${___arr[5]}" plugin "$___user" "$___plugin" "$___id_as" "$___pdir_orig" "${${___key##(zinit|z-annex) hook:}%% <->}" load || \
|
||||
return $(( 10 - $? ))
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ $___user != % && ! -d ${ZINIT[PLUGINS_DIR]}/${___id_as//\//---} ]] {
|
||||
|
|
|
|||
Loading…
Reference in a new issue