Use robust shell escaping based on Python's shlex.quote()#8
Merged
tobi merged 1 commit intotobi:masterfrom Dec 2, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the shell_escape() function to adopt Python's shlex.quote() approach, where strings are wrapped in single quotes with proper escaping of embedded single quotes.
Key Changes:
- Moved
shell_escape()implementation earlier in the file (before its first use) and updated it to wrap strings in single quotes, making all characters literal except single quotes themselves - Updated all shell script builders (
build_cd_script,build_mkdir_script,build_clone_script,build_delete_script,build_worktree_script) to use the new escaping function and removed manual quotes from format strings - Applied shell escaping to paths in
cmd_init()for both Fish and Bash/Zsh shell function generation
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Simplify
shell_escape()to always wrap strings in single quotes, matching Python'sshlex.quote()approach. In POSIX shells, single quotes protect all characters except the single quote itself, so newlines and other special characters no longer need rejection—they're literal inside single quotes.