Skip to content

fix: complete literal bracketed file paths - #1811

Merged
kmvanbrunt merged 1 commit into
python-cmd2:mainfrom
anticipate218:fix/literal-path-completion
Nov 14, 2026
Merged

kmvanbrunt merged 1 commit into
python-cmd2:mainfrom
anticipate218:fix/literal-path-completion

Conversation

@anticipate218

Copy link
Copy Markdown
Contributor

Fixes #1810.

File paths containing square brackets are currently interpreted as glob patterns during completion. For example, completing [ab] can select a.txt instead of the existing [ab].txt; a bracketed working directory can make even blank completion return no results.

This change escapes the fully expanded literal path before adding the completion wildcard. Tilde restoration, directory suffixes, path filters, and the existing rejection of typed * / ? remain unchanged. Eight regression cases cover literal filenames, absolute and relative paths, blank and prefixed completion from a bracketed working directory, home expansion, and directory filtering.

Validation on Windows / Python 3.15.2:

  • The eight regression cases fail against the unmodified implementation and pass with the fix.
  • Full repository test command, uv run python -Xutf8 -m pytest tests: 2,788 passed, 174 skipped.
  • uv lock --locked, uv run ty check, uv run mypy ., and uv run zensical build -s passed.
  • All 14 configured pre-commit checks passed. The original prek run -a could not initialize the typos hook because its Git fetch stalled. A temporary configuration outside the repository ran the same hooks, substituting only the typos source install with the pinned PyPI package typos==1.52.2; the executable reports typos-cli 1.52.2. No repository hook or CI configuration is changed.

make is unavailable in this environment, so its recipe commands were invoked directly through uv. The Linux/macOS and other Python-version matrix was not run locally. The full test run left all 235 tracked source file hashes unchanged.

AI assistance: the implementation, regression tests, and this description were prepared with OpenAI Codex.

@codecov

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.75%. Comparing base (593580e) to head (d84fc8f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1811   +/-   ##
=======================================
  Coverage   99.75%   99.75%           
=======================================
  Files          23       23           
  Lines        6609     6609           
=======================================
  Hits         6593     6593           
  Misses         16       16           
Flag Coverage Δ
unittests 99.75% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@kmvanbrunt
kmvanbrunt merged commit c2eef0b into python-cmd2:main Nov 14, 2026
32 checks passed
@anticipate218

Copy link
Copy Markdown
Contributor Author

Thank you for reviewing and merging the fix.

@kmvanbrunt

Copy link
Copy Markdown
Member

@anticipate218 Thanks for the fix. I included it in another cmd2 function (#1812).

@anticipate218

Copy link
Copy Markdown
Contributor Author

Thanks for extending this to get_exes_in_path() and adding the PATH-directory regression cases as well.

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.

Path completion interprets literal square brackets as glob patterns

2 participants