Skip to content

Member tab completion fails to quote member names not directly acceptable #10198

Closed

Description

@msftrncs

Continuing my investigation of tab completion quoting/escaping failures:

Steps to reproduce

$a = @{ '3hello' = 'a'}

$a.<TAB> # select `3hello` property from list, then execute.

Expected behavior

the finished completion to be:

$a.'3hello'

Actual behavior

$a.3hello

Which causes an error 'missing property name'.

Environment data

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

Additionally

Tab completion after $a.' switches to file name completion.

The code that handles this appears to be at:

// Handle scenarios like this: $aa | add-member 'a b' 23; $aa.a<tab>
if (completionText.IndexOfAny(s_charactersRequiringQuotes) != -1)
{
completionText = completionText.Replace("'", "''");
completionText = "'" + completionText + "'";
}

The field s_charactersRequiringQuotes is used mostly for variable name checks, but is also inadequate for that purpose (see #10006), but fails here because it doesn't handle the condition of numeric digits in the first character require quoting.

private static readonly char[] s_charactersRequiringQuotes = new char[] {
'-', '`', '&', '@', '\'', '"', '#', '{', '}', '(', ')', '$', ',', ';', '|', '<', '>', ' ', '.', '\\', '/', '\t', '^',
};

In PowerShell code, I would use REGEX: ^[\p{L}_][\w]*$. If this regex fails on a non-empty name, the property name must be quoted. However there is probably a quicker method in C# using the [CharExtensions] class using IsIdentifierStart() (first character) and IsIdentifierFollow() (subsequent characters), and quote the property if the response is FALSE.

Activity

  1. added
    Issue-Question
    on Jul 21, 2019
  2. msftrncs commented on Jul 22, 2019

    @msftrncs
    ContributorAuthor

    I have a start to a PR for this issue. I've created a new member of CodeGeneration to check for and quote member names when they need it.

  3. added a commit that references this issue on Jul 22, 2019
    0fc1723
  4. added
    WG-Engine
    on Jul 22, 2019
  5. added a commit that references this issue on Dec 2, 2019
    feb11ae
  6. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  7. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  8. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  9. added
    Resolution-No Activity
    on Nov 16, 2023
  10. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

  11. added
    In-PR
    on Mar 4, 2025
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

    In-PRIssue-QuestionResolution-No ActivityWG-Engine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions