Skip to content

fix: preserve argv boundaries in spin run and spin exec#185

Open
yusufkandemir wants to merge 1 commit into
serversideup:mainfrom
yusufkandemir:fix/run-argv-mangling
Open

fix: preserve argv boundaries in spin run and spin exec#185
yusufkandemir wants to merge 1 commit into
serversideup:mainfrom
yusufkandemir:fix/run-argv-mangling

Conversation

@yusufkandemir
Copy link
Copy Markdown

Problem

spin run and spin exec lose argument boundaries when any argument contains a space or quoted string. Minimal reproduction:

spin run --quiet php php -r 'echo "hi";'
# [19-May-2026 20:00:00 UTC] PHP Parse error:  syntax error, unexpected end of file in Command line code on line 1

The single-quoted PHP source arrives at the container split into two tokens (echo and "hi";), so PHP only sees echo. Same problem causes any spin run php php artisan tinker --execute '...' to fail with similar errors as well. This is especially a big deal with AI agents since Tinker and PHP REPL are important to quickly test/verify certain things.

Cause

local args=($(filter_out_spin_arguments "$@"))

filter_out_spin_arguments returned its result via echo "${filtered[@]}" (space-joined, unquoted), and the caller word-split that back on IFS. Every argument containing whitespace is gone before reaching docker compose run.

lib/actions/exec.sh had a smaller variant of the same problem: bare $@ instead of "$@".

Fix

Use a global-array return-based solution. The same pattern is also used by the existing prepare_ansible_run.

  • filter_out_spin_arguments now writes to SPIN_FILTERED_ARGS
  • run.sh copies it into a local array to make the usage easier, preserving the previous DX
  • exec.sh quotes "$@".

Bash 3.2 compatibility is required as noted in AGENTS.md(I'd recommend creating a contributing.md or similar, or putting the same requirement elsewhere too). So, I didn't use the nameref(local -n) approach, which would've helped avoid introducing global variables, but it only works in Bash 4.3+.

filter_out_spin_arguments returned its result via echo (space-joined,
unquoted) and the caller word-split it back on IFS, destroying any
argument containing whitespace. `spin run --quiet php php -r 'echo "hi";'`
reached PHP as `echo` + `"hi";` (two tokens), causing parse errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant