Skip to content

tab completion of arguments (file paths, variable names, etc) fails to escape some special characters #9881

@msftrncs

Description

@msftrncs

EDIT: 2019-06-25 - Additional conditions and clarifications, corrected expected behavior as requiring the curly quotes to be doubled, added second example demonstrating the tab completion when the first character of the file name is not a quote character, added third example for curly double quotes

I am not sure what is really responsible for tab completion of path names in PowerShell, but here is what I found while testing a similar function in posh-git.

Steps to reproduce

Example 1

echo hello >"`u{2018}hello`u{2019}.txt"

get-content   # press tab until file `.\‘hello’.txt` is shown

Example 2

echo hello >"hello`u{2019}.txt"

get-content   # press tab until file `'.\hello’.txt'` is shown

Example 3

echo hello >"hello`u{201C}.txt"

get-content  "hello" # press tab until file `".\hello“.txt"` is shown

Expected behavior

Example 1

get-content '.\‘‘hello’’.txt'

Example 2

get-content '.\hello’’.txt'

Example 3

get-content ".\hello““.txt"

Actual behavior

Example 1

get-content .\hello.txt

This generates an error saying the file hello.txt cannot be found. Note this particular behavior is regardless of the type of quote used, as long as the quote is a legal filename character and is at the start of the file name and is a special character for PowerShell.

Example 2

get-content '.\hello.txt'

This will cause PSReadLine to want to continue a multiline input because the quoted string is still open.

Example 3

get-content ".\hello.txt"

This will cause PSReadLine to want to continue a multiline input because the quoted string is still open.

Environment data

Name                           Value
----                           -----
PSVersion                      6.2.0
PSEdition                      Core
GitCommitId                    6.2.0
OS                             Microsoft Windows 10.0.18912
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

In dahlbyk/posh-git#683 (comment) @rkeithhill commented that it would be nice if PowerShell has a static method for escaping arguments, and it was that comment that triggered me to test this possibility. I have not tried to test all characters that could be special but found in file names to see if any more are missing escaping.

Another issue with tab completion, server/share names with spaces, #7569, but this only affects the path while it is just '\server\share with a space'...

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-PRIndicates that a PR is out for the issueIssue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreWG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions