Skip to content

Use robust shell escaping based on Python's shlex.quote()#8

Merged
tobi merged 1 commit intotobi:masterfrom
ianks:fix/shell-injection-all
Dec 2, 2025
Merged

Use robust shell escaping based on Python's shlex.quote()#8
tobi merged 1 commit intotobi:masterfrom
ianks:fix/shell-injection-all

Conversation

@ianks
Copy link
Copy Markdown
Contributor

@ianks ianks commented Dec 1, 2025

Simplify shell_escape() to always wrap strings in single quotes, matching Python's shlex.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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@tobi tobi merged commit ed1c0e6 into tobi:master Dec 2, 2025
6 checks passed
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.

3 participants