bugfix(prompting): shlex-parse $EDITOR + thread input_fn through editor fallback#12
Open
CryptoJones wants to merge 1 commit into
Open
bugfix(prompting): shlex-parse $EDITOR + thread input_fn through editor fallback#12CryptoJones wants to merge 1 commit into
CryptoJones wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two related bugs in prompting.py:
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).
_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):
150/150 tests pass; ruff + mypy clean.