-
-
Notifications
You must be signed in to change notification settings - Fork 763
fix: handle Python paths with spaces correctly #445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
abe238
wants to merge
15
commits into
AndyMik90:develop
Choose a base branch
from
abe238:fix/python-path-spaces
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,394
−67
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
890704c
fix: handle Python paths with spaces correctly
abe238 01f6300
fix: address code review feedback
abe238 3f40409
auto-claude: subtask-1-1 - Add ShellType type and detectShellType() f…
abe238 55f3229
auto-claude: subtask-1-2 - Add escapeShellArgPowerShell() function fo…
abe238 305b0a4
auto-claude: subtask-1-3 - Add buildCdCommandForShell() function
abe238 4a43179
auto-claude: subtask-2-1 - Create shell-escape.test.ts with tests for…
abe238 7c2ea5d
auto-claude: subtask-2-2 - Add tests for buildCdCommandForShell() wit…
abe238 21546df
auto-claude: subtask-2-3 - Add tests for escapeShellArgPowerShell()
abe238 8b06b0c
auto-claude: subtask-3-1 - Update invokeClaude() to accept and use sh…
abe238 326eac3
auto-claude: subtask-3-2 - Update profile-based Claude invocation for…
abe238 5252f6d
auto-claude: subtask-4-1 - Update profile login commands in terminal-…
abe238 ccdb0b2
auto-claude: subtask-5-1 - Add shell type tracking to TerminalProcess
abe238 2dffc16
auto-claude: subtask-6-2 - Verify backward compatibility - existing b…
abe238 85e230f
fix(security): harden shell escaping with newline injection prevention
abe238 a79a02d
fix: address code review feedback for python-detector
abe238 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
151 changes: 151 additions & 0 deletions
151
apps/frontend/src/main/__tests__/python-detector.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| import { parsePythonCommand, validatePythonPath } from '../python-detector'; | ||
|
|
||
| describe('parsePythonCommand', () => { | ||
| describe('paths with spaces', () => { | ||
| it('should preserve paths with spaces when they contain path separators', () => { | ||
| const [cmd, args] = parsePythonCommand('/Users/user/Library/Application Support/MyApp/venv/bin/python'); | ||
| expect(cmd).toBe('/Users/user/Library/Application Support/MyApp/venv/bin/python'); | ||
| expect(args).toEqual([]); | ||
| }); | ||
|
|
||
| it('should preserve Windows paths with spaces', () => { | ||
| const [cmd, args] = parsePythonCommand('C:\\Program Files\\Python310\\python.exe'); | ||
| expect(cmd).toBe('C:\\Program Files\\Python310\\python.exe'); | ||
| expect(args).toEqual([]); | ||
| }); | ||
|
|
||
| it('should preserve macOS Application Support paths', () => { | ||
| const [cmd, args] = parsePythonCommand('/Users/testuser/Library/Application Support/Auto-Claude/python-venv/bin/python3'); | ||
| expect(cmd).toBe('/Users/testuser/Library/Application Support/Auto-Claude/python-venv/bin/python3'); | ||
| expect(args).toEqual([]); | ||
| }); | ||
|
|
||
| it('should preserve paths with multiple spaces', () => { | ||
| const [cmd, args] = parsePythonCommand('/path/with multiple spaces/python3'); | ||
| expect(cmd).toBe('/path/with multiple spaces/python3'); | ||
| expect(args).toEqual([]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('simple commands', () => { | ||
| it('should split "py -3" into command and args', () => { | ||
| const [cmd, args] = parsePythonCommand('py -3'); | ||
| expect(cmd).toBe('py'); | ||
| expect(args).toEqual(['-3']); | ||
| }); | ||
|
|
||
| it('should handle plain python command', () => { | ||
| const [cmd, args] = parsePythonCommand('python3'); | ||
| expect(cmd).toBe('python3'); | ||
| expect(args).toEqual([]); | ||
| }); | ||
|
|
||
| it('should handle python with version', () => { | ||
| const [cmd, args] = parsePythonCommand('python'); | ||
| expect(cmd).toBe('python'); | ||
| expect(args).toEqual([]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('quoted paths', () => { | ||
| it('should strip double quotes from paths', () => { | ||
| const [cmd, args] = parsePythonCommand('"/path/to/python"'); | ||
| expect(cmd).toBe('/path/to/python'); | ||
| expect(args).toEqual([]); | ||
| }); | ||
|
|
||
| it('should strip single quotes from paths', () => { | ||
| const [cmd, args] = parsePythonCommand("'/path/to/python'"); | ||
| expect(cmd).toBe('/path/to/python'); | ||
| expect(args).toEqual([]); | ||
| }); | ||
|
|
||
| it('should handle quoted paths with spaces', () => { | ||
| const [cmd, args] = parsePythonCommand('"/Users/user/My Apps/venv/bin/python"'); | ||
| expect(cmd).toBe('/Users/user/My Apps/venv/bin/python'); | ||
| expect(args).toEqual([]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('edge cases', () => { | ||
| it('should throw on empty string', () => { | ||
| expect(() => parsePythonCommand('')).toThrow('Python command cannot be empty'); | ||
| }); | ||
|
|
||
| it('should throw on whitespace-only string', () => { | ||
| expect(() => parsePythonCommand(' ')).toThrow('Python command cannot be empty'); | ||
| }); | ||
|
|
||
| it('should throw on empty quoted string', () => { | ||
| expect(() => parsePythonCommand('""')).toThrow('Python command cannot be empty'); | ||
| }); | ||
|
|
||
| it('should handle path with trailing spaces', () => { | ||
| const [cmd, args] = parsePythonCommand('/path/to/python '); | ||
| expect(cmd).toBe('/path/to/python'); | ||
| expect(args).toEqual([]); | ||
| }); | ||
|
|
||
| it('should handle path with leading spaces', () => { | ||
| const [cmd, args] = parsePythonCommand(' /path/to/python'); | ||
| expect(cmd).toBe('/path/to/python'); | ||
| expect(args).toEqual([]); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('validatePythonPath', () => { | ||
| describe('shell metacharacter rejection', () => { | ||
| it('should reject paths with command substitution $()', () => { | ||
| const result = validatePythonPath('/path/$(whoami)/python'); | ||
| expect(result.valid).toBe(false); | ||
| expect(result.reason).toContain('dangerous shell metacharacters'); | ||
| }); | ||
|
|
||
| it('should reject paths with backticks', () => { | ||
| const result = validatePythonPath('/path/`id`/python'); | ||
| expect(result.valid).toBe(false); | ||
| expect(result.reason).toContain('dangerous shell metacharacters'); | ||
| }); | ||
|
|
||
| it('should reject paths with semicolons', () => { | ||
| const result = validatePythonPath('/path/python; rm -rf /'); | ||
| expect(result.valid).toBe(false); | ||
| expect(result.reason).toContain('dangerous shell metacharacters'); | ||
| }); | ||
|
|
||
| it('should reject paths with pipes', () => { | ||
| const result = validatePythonPath('/path/python | cat'); | ||
| expect(result.valid).toBe(false); | ||
| expect(result.reason).toContain('dangerous shell metacharacters'); | ||
| }); | ||
|
|
||
| it('should reject paths with newlines', () => { | ||
| const result = validatePythonPath('/path/python\nrm -rf /'); | ||
| expect(result.valid).toBe(false); | ||
| expect(result.reason).toContain('dangerous shell metacharacters'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('path traversal rejection', () => { | ||
| it('should reject paths with directory traversal', () => { | ||
| const result = validatePythonPath('/usr/bin/../../../etc/passwd'); | ||
| expect(result.valid).toBe(false); | ||
| // Path traversal is caught by allowlist check (normalized path won't match patterns) | ||
| expect(result.reason).toContain('does not match allowed Python locations'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('empty/invalid input', () => { | ||
| it('should reject empty string', () => { | ||
| const result = validatePythonPath(''); | ||
| expect(result.valid).toBe(false); | ||
| expect(result.reason).toContain('empty or invalid'); | ||
| }); | ||
|
|
||
| it('should reject null-like values', () => { | ||
| const result = validatePythonPath(null as unknown as string); | ||
| expect(result.valid).toBe(false); | ||
| }); | ||
| }); | ||
| }); | ||
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add Jest type definitions to fix pipeline failure.
The CI pipeline reports
Cannot find name 'describe'. The test file needs Jest type definitions to compile.🔎 Proposed fix
Add the import at the top of the file or install
@types/jest:+/// <reference types="jest" /> import { parsePythonCommand, validatePythonPath } from '../python-detector'; describe('parsePythonCommand', () => {Alternatively, ensure
@types/jestis installed and included intsconfig.json:📝 Committable suggestion
🧰 Tools
🪛 GitHub Actions: CI
[error] 3-3: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try 'npm i --save-dev @types/jest' or 'npm i --save-dev @types/mocha'.
🤖 Prompt for AI Agents