Skip to content

bugfix(prompting): shlex-parse $EDITOR + thread input_fn through editor fallback#12

Open
CryptoJones wants to merge 1 commit into
mainfrom
bugfix/prompting-shlex-and-input-fn
Open

bugfix(prompting): shlex-parse $EDITOR + thread input_fn through editor fallback#12
CryptoJones wants to merge 1 commit into
mainfrom
bugfix/prompting-shlex-and-input-fn

Conversation

@CryptoJones
Copy link
Copy Markdown
Owner

Two related bugs in prompting.py:

  1. editor_command() did cmd.split() on the env value, which doesn't
    honor shell quoting. Concrete failure:

    EDITOR="emacsclient -a 'emacs'" -> ['emacsclient', '-a', "'emacs'"]

    The stray quotes get passed to subprocess.run as a literal,
    emacsclient is invoked with an alternate that doesn't exist, fails
    to find a fallback editor, and the multiline answer is lost.

    Fix: shlex.split() honors POSIX-style quoting. Falls back to naive
    split if the user's EDITOR has unbalanced quotes (better than
    returning None silently).

  2. _ask_multiline_editor's "no editor found" fallback path called
    _ask_multiline(input, output_fn, q) — using the BUILTIN input
    instead of the input_fn parameter. That bypassed test mocks AND,
    on real runs, meant the operator's input was read from raw stdin
    even when the caller had wired up a special handler (REPL, pipe, etc.).

    Fix: thread input_fn through _ask_multiline_editor as a kwarg with
    default=input, and pass it down to both the fallback path and the
    "required field, re-open editor" recursion.

    Public signature of ask() unchanged; just an extra plumbing argument
    on a private function.

Tests added (3):

  • EDITOR="emacsclient -a 'emacs'" -> ['emacsclient', '-a', 'emacs']
  • EDITOR with double-quoted Windows-style path with spaces survives
  • EDITOR with unbalanced quotes doesn't crash, falls back to naive split

150/150 tests pass; ruff + mypy clean.

…tor fallback

Two related bugs in prompting.py:

1. editor_command() did cmd.split() on the env value, which doesn't
   honor shell quoting. Concrete failure:

     EDITOR="emacsclient -a 'emacs'"   ->   ['emacsclient', '-a', "'emacs'"]

   The stray quotes get passed to subprocess.run as a literal,
   emacsclient is invoked with an alternate that doesn't exist, fails
   to find a fallback editor, and the multiline answer is lost.

   Fix: shlex.split() honors POSIX-style quoting. Falls back to naive
   split if the user's EDITOR has unbalanced quotes (better than
   returning None silently).

2. _ask_multiline_editor's "no editor found" fallback path called
   _ask_multiline(input, output_fn, q) — using the BUILTIN input
   instead of the input_fn parameter. That bypassed test mocks AND,
   on real runs, meant the operator's input was read from raw stdin
   even when the caller had wired up a special handler (REPL, pipe, etc.).

   Fix: thread input_fn through _ask_multiline_editor as a kwarg with
   default=input, and pass it down to both the fallback path and the
   "required field, re-open editor" recursion.

   Public signature of ask() unchanged; just an extra plumbing argument
   on a private function.

Tests added (3):
- EDITOR="emacsclient -a 'emacs'" -> ['emacsclient', '-a', 'emacs']
- EDITOR with double-quoted Windows-style path with spaces survives
- EDITOR with unbalanced quotes doesn't crash, falls back to naive split

150/150 tests pass; ruff + mypy clean.
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