Fix unsafe bash command replacement - use token-by-token matching#56
Merged
yannrichet merged 1 commit intomainfrom Nov 27, 2025
Merged
Fix unsafe bash command replacement - use token-by-token matching#56yannrichet merged 1 commit intomainfrom
yannrichet merged 1 commit intomainfrom
Conversation
yannrichet-asnr
pushed a commit
that referenced
this pull request
Feb 13, 2026
Squash-merge of implement-algorithms branch onto current main (v0.9.1). Resolved conflicts in: - fz/__init__.py: Added both fzl and fzd exports - fz/core.py: Merged imports, kept callbacks from main + added fzd functions - fz/helpers.py: Kept main's format_time (Windows bash moved to shell.py) - fz/cli.py: Kept fzl list command + added algorithm install subcommands - fz/shell.py: Kept main's safer regex replacement from #56 - README.md: Listed both fzl and fzd, kept improved env var docs - tests/test_cli_commands.py: Added new test methods from PR - Removed CLAUDE.md (moved to claude/ dir on main) - Removed setup.py (replaced by pyproject.toml on main)
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.
Summary
Fixes unsafe bash command replacement in
fz/shell.pythat could incorrectly replace "bash" when it's part of URIs, file paths, or filenames. Implements safe token-by-token replacement that only replaces standalone "bash" command.Problem
The previous implementation used simple string replacement or regex patterns that could incorrectly replace "bash" in:
sh://C:/dir/bash.exe/usr/bin/bash,C:\msys64\usr\bin\bash.exebash.sh,mybashBASH_VERSION,womealphbashSolution
Implemented token-by-token safe replacement in
fz/shell.py:This approach:
Changes
Code Changes
safe_replace_bash()functionreplace_commands_in_string()already uses safe regex patternsTest Coverage
TestSafeBashReplacementclass with 3 comprehensive test methods:test_bash_replacement_only_standalone_word()- Integration testtest_safe_replace_bash_function_logic()- Unit test with 12 test casestest_command_parsing_preserves_non_bash_tokens()- 5 command parsing scenariosTest Cases Covered
✅ Should NOT be replaced:
✅ SHOULD be replaced:
Testing
All 28 tests in
test_shell_path.pypass:Codebase Audit
Performed comprehensive search for unsafe replacements:
.replace('bash')in source code.replace('grep'),.replace('awk'), etc.replace_commands_in_string()method already uses proper regex word boundariesRelated
This PR is rebased on main and includes the merge of safe bash replacement improvements.
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com