mirror of
https://github.com/zdharma-continuum/zinit.git
synced 2026-09-10 07:36:38 -04:00
64 lines
2 KiB
Bash
Executable file
64 lines
2 KiB
Bash
Executable file
#!/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 |