Skip to content

Completion of hash table key has invalid replacement index/length #5322

@lzybkr

Description

@lzybkr

Steps to reproduce

$line = 'gps | format-table -Property @{'
$exp = TabExpansion2 $line $line.Length
$exp.ReplacementIndex
$exp.ReplacementLength
$exp.CompletionMatches.Count

Expected behavior

ReplacementIndex should be $line.Length, the length should be 0.

31
0
5

If you change the repro to add a space at the end, then you will see 32, 0, 5

$line = 'gps | format-table -Property @{ '

Actual behavior

The replacement index and length are negative.

-1
-1
5

This raises an exception in PSReadLine (PowerShell/PSReadLine#534)
In Windows PowerShell, if you remove PSReadLine and try tab interactively (instead of manually calling TabExpansion2), PowerShell will crash - as in exit after reporting a crash to Watson.
PowerShell ISE doesn't crash, but it also doesn't complete anything.

Environment data

> $PSVersionTable

Name                           Value                                                                                   
----                           -----                                                                                   
PSVersion                      5.1.16299.19                                                                            
PSEdition                      Desktop                                                                                 
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                 
BuildVersion                   10.0.16299.19                                                                           
CLRVersion                     4.0.30319.42000                                                                         
WSManStackVersion              3.0                                                                                     
PSRemotingProtocolVersion      2.3                                                                                     
SerializationVersion           1.1.0.1                                                                                 



Name                           Value                                                                                   
----                           -----                                                                                   
PSVersion                      6.0.0-beta.9                                                                            
PSEdition                      Core                                                                                    
GitCommitId                    v6.0.0-beta.9                                                                           
OS                             Microsoft Windows 10.0.16299                                                            
Platform                       Win32NT                                                                                 
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                 
PSRemotingProtocolVersion      2.3                                                                                     
SerializationVersion           1.1.0.1                                                                                 
WSManStackVersion              3.0                                                                                     

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions