Skip to content

Commit

Permalink
Avoid side-effects from RC_EXPAND_PARAM in async_job (#15)
Browse files Browse the repository at this point in the history
RC_EXPAND_PARAM expands each item in the array with whatever is left or
right of it, in this case $'\0' which terminated the command early.
  • Loading branch information
derimagia authored and mafredri committed Feb 12, 2017
1 parent e702ec4 commit 2a8781d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion async.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ async_job() {
cmd=(${(q)cmd}) # Quote special characters in multi argument commands.
fi

zpty -w $worker $cmd$'\0'
# Quote the cmd in case RC_EXPAND_PARAM is set.
zpty -w $worker "$cmd"$'\0'
}

# This function traps notification signals and calls all registered callbacks
Expand Down
20 changes: 20 additions & 0 deletions async_test.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,26 @@ test_async_worker_survives_termination_of_other_worker() {
(( $#result == 5 )) || t_error "wanted a result, got (${(@Vq)result})"
}

test_async_job_with_rc_expand_param() {
setopt localoptions rcexpandparam

# Make sure to test with multiple options
local -a result
cb() { result=("$@") }

async_start_worker test
async_job test print "hello world"
while ! async_process_results test cb; do :; done
async_stop_worker test

[[ $result[1] = print ]] || t_error "want command name: print, got" $result[1]
[[ $result[2] = 0 ]] || t_error "want exit code: 0, got" $result[2]

[[ $result[3] = "hello world" ]] || {
t_error "want output: \"hello world\", got" ${(Vq-)result[3]}
}
}

zpty_init() {
zmodload zsh/zpty

Expand Down

0 comments on commit 2a8781d

Please sign in to comment.