Skip to content

shell_cmd_complete() ignores forward slashes on Windows when deciding whether text is a bare command name #1820

Open

Description

@tleonhardt

Found while reviewing #1812. Analysed from the code; not yet reproduced on a Windows machine.

Problem

Cmd.shell_cmd_complete() decides whether the text being completed is a bare command name (to be completed from PATH) or a path (to be completed by path_complete()) with this check:

if not text.startswith("~") and os.path.sep not in text:
    items = [CompletionItem(exe) for exe in utils.get_exes_in_path(text)]
    return Completions(items=items)

On Windows os.path.sep is a backslash, but a forward slash (os.path.altsep) is a path separator as well. Text which uses forward slashes is therefore treated as a bare command name and sent to get_exes_in_path().

Expected consequences on Windows

  • shell C:/tools/my + Tab calls get_exes_in_path("C:/tools/my"). os.path.join(path_dir, "C:/tools/my") discards the PATH directory, the glob matches C:/tools/mytool.exe, and only the basename is returned. The typed C:/tools/my is replaced by mytool.exe and the directory is lost.
  • shell ./my + Tab searches each PATH directory for ./my* and so lists executables on PATH, not files in the current working directory.

Suggested fix

Also check os.path.altsep (when it is not None) so this text is routed to path_complete(). The comment above the check says "no ~ or path separator", which should then be true on every platform.

A test will need to run on Windows, or patch os.path.sep/os.path.altsep.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions