fix(tui): handle quotes in VISUAL/EDITOR env vars
Fixes #7749
I noticed this issue was assigned but didn't active PR, so I went ahead and fixed it. Happy to collaborate with @assignee if they're also working on this.
What does this PR do?
Fixes the /editor command to correctly handle VISUAL or EDITOR environment variables that contain quoted arguments.
The Problem
When VISUAL contains arguments with quotes like:
```bash
export VISUAL="nvim --cmd 'let g:flatten_wait=1'"
```
The current implementation splits on spaces (`editor.split(" ")`), breaking the quoted argument:
- Expected: `nvim --cmd "let g:flatten_wait=1"`
- Actual: `nvim --cmd 'let g:flatten_wait=1'` (parsed as 4 separate args)
This causes nvim to fail with: `E20: Mark not set: 'let`
The Solution
Use shell execution (`sh -c` on Unix, `cmd /c` on Windows) to properly parse quotes and arguments, just like git, ranger, and other CLI tools handle editor invocation.
Also added filepath escaping to prevent command injection attacks.
How did you verify your code works?
-
Unit tests: Added comprehensive tests in `test/util/editor.test.ts`
- All 5 tests passing
- 100% coverage on editor.ts
- Tests cover: simple editor, quoted arguments, multiple arguments, fallback to EDITOR, no editor set
-
Type checking: Pre-commit hooks passed (turbo typecheck)
Changes
- Modified `src/cli/cmd/tui/util/editor.ts` to use shell execution
- Added filepath escaping for security (`'${filepath.replace(/'/g, "'\''")}`)
- Added comprehensive unit tests in `test/util/editor.test.ts`