Skip to content

Fix cd command parsing for quotes and empty arguments#322

Merged
sloria merged 2 commits intosloria:mainfrom
ArmaanjeetSandhu:fix/cd-quoted-paths
Feb 16, 2026
Merged

Fix cd command parsing for quotes and empty arguments#322
sloria merged 2 commits intosloria:mainfrom
ArmaanjeetSandhu:fix/cd-quoted-paths

Conversation

@ArmaanjeetSandhu
Copy link
Copy Markdown
Contributor

This PR fixes two issues with the internal cd command implementation in the interactive player:

  1. Quoted Paths: Previously, run_command used cmd.split()[1] to extract the directory argument. This failed for paths with spaces (e.g., cd "my dir") because split() would break the quoted string into multiple parts.
  2. Bare cd command: Running cd without arguments caused an IndexError because the code blindly accessed index 1.

Changes:

  • src/doitlive/keyboard.py: Updated run_command to utilize the command_as_list (parsed by shlex) instead of manual splitting.
  • src/doitlive/keyboard.py: Added logic to default to ~ (HOME) if no directory argument is provided, mirroring standard shell behavior.
  • Tests: Added a new test case test_cd_spaces and a session file tests/sessions/cd_spaces.session to verify that directories with spaces are handled correctly.

ArmaanjeetSandhu and others added 2 commits February 17, 2026 04:14
- Replace naive `cmd.split()[1]` with `shlex` parsed arguments to correctly handle directory names containing spaces (e.g., `cd "test dir"`)
- Add check for argument length to support the bare `cd` command; defaults to HOME (`~`) instead of raising an `IndexError`
- Add regression test `test_cd_spaces` and corresponding session file
@sloria
Copy link
Copy Markdown
Owner

sloria commented Feb 16, 2026

Thanks!

@sloria sloria enabled auto-merge (squash) February 16, 2026 23:02
@sloria sloria merged commit 8141b87 into sloria:main Feb 16, 2026
6 checks passed
@ArmaanjeetSandhu ArmaanjeetSandhu deleted the fix/cd-quoted-paths branch February 16, 2026 23:19
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.

2 participants