Skip to content

exception ArgumentOutOfRangeException with setup "Tab to MenuComplete" and "HistorySearchCursorMovesToEnd" #3559

@freetomik

Description

@freetomik

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues, especially the pinned issues.

Exception report

System.ArgumentOutOfRangeException: Index and length must refer to a location within the string. (Parameter 'length')
   at System.String.ThrowSubstringArgumentOutOfRange(Int32 startIndex, Int32 length)
   at System.String.Substring(Int32 startIndex, Int32 length)
   at Microsoft.PowerShell.PSConsoleReadLine.MenuCompleteImpl(Menu menu, CommandCompletion completions)
   at Microsoft.PowerShell.PSConsoleReadLine.PossibleCompletionsImpl(CommandCompletion completions, Boolean menuSelect)
   at Microsoft.PowerShell.PSConsoleReadLine.CompleteImpl(Boolean menuSelect)
   at Microsoft.PowerShell.PSConsoleReadLine.MenuComplete(Nullable`1 key, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(PSKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken, Nullable`1 lastRunStatus)

Screenshot

PSReadLine_bug

Environment data

PS Version: 7.3.2
PS HostName: ConsoleHost (Windows Terminal)
PSReadLine Version: 2.2.6
PSReadLine EditMode: Windows
OS: 10.0.19041.320 (WinBuild.160101.0800)
BufferWidth: 202
BufferHeight: 60

Steps to reproduce

  1. run Set-PSReadlineKeyHandler -Chord Tab -Function MenuComplete to enable menu completion with tab key
  2. run Set-PSReadLineOption -HistorySearchCursorMovesToEnd to move cursor to the end after history search
  3. have folders strong and stronghold in current empty folder
  4. type following keys:
    c d Spacebar s Tab h Tab Backspace h

Expected behavior

No exception.

Actual behavior

The above exception happens.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-StabilityLabel for tracking stability IssuesIssue-BugIt either shouldn't be doing this or needs an investigation.Resolution-Fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions