Skip to content

Quote the eval argument, so bash-quoted arguments survive - #115

Open
fowlie wants to merge 1 commit into
edc:masterfrom
fowlie:quote-eval-argument
Open

fowlie wants to merge 1 commit into
edc:masterfrom
fowlie:quote-eval-argument

Conversation

@fowlie

@fowlie fowlie commented Sep 8, 2026

Copy link
Copy Markdown

eval $1 in __bass.py is unquoted, so bash performs word splitting and pathname
expansion on the command string before eval parses it. Quoting that is correct for
bash therefore does not survive the round trip.

$ bass printf "'[%s]\n'" "'a  b'"
[a b]                       # one space; the argument was quoted for bash

$ bass printf "'[%s]\n'" "'*'"
[LICENSE]
[Makefile]
[README.md]
[functions]
[test]                      # a quoted glob, expanded against the cwd

With eval "$1" the string reaches eval intact and both behave as the quoting asks:
[a b], and [*].

This is #105. It shows up whenever a caller quotes properly on the fish side — which is
what a fish wrapper around bass has to do, since fish strips its own quotes before bass
ever sees the arguments.

What this deliberately does not change

bass's contract is that its arguments form a bash command line, and that stays true:

  • bass source ~/.nvm/nvm.sh --no-use ';' nvm use iojs still works — ';' reaches bash
    as a separator, exactly as the README documents.
  • An unquoted * is still a glob, because at that point it is shell syntax the caller
    wrote, not data.

The only difference is that quoting is no longer stripped before bash can honour it.

Test

test/test_quoted_arguments.fish asserts both symptoms and is wired into make test. It
fails on the unpatched version (no Success, exit 1) and passes with the change. The four
existing tests still pass.

Fixes edc#105. `eval $1` is unquoted, so bash performs word splitting and
pathname expansion on the command string before `eval` parses it. Quoting
that is correct *for bash* therefore does not survive the round trip:

    bass printf "'[%s]\n'" "'a  b'"   ->  [a b]     (one space)
    bass printf "'[%s]\n'" "'*'"      ->  expanded against the cwd

`eval "$1"` hands the string to eval intact, and both cases behave as the
quoting asks: `[a  b]`, and `[*]`.

This deliberately does not change bass's contract that unquoted arguments
form a bash command line -- `bass source ~/.nvm/nvm.sh ';' nvm use iojs`
still relies on `';'` reaching bash as a separator, and an unquoted `*` is
still a glob. The only difference is that quoting is no longer stripped
before bash can honour it.

The new test asserts both symptoms and fails on the unpatched version.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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