Exception when deleting invalid command retained from ValidateAndAcceptLine in Vi Mode

Open
#3,919 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp
Domain
cli

Research direction

Reproduce the sequence in a profile-free pwsh session: Vi mode, bind Enter to ValidateAndAcceptLine, enter an invalid command, press Escape, then dd. Start from the ValidateAndAcceptLine and ViChordHandler paths shown in the exception, and verify that deleting the current input completes without the IndexOutOfRangeException.

Written by the indexing model from the issue text.

Description

Issue-Bug Needs-More Investigation
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
### Environment
PSReadLine: 2.3.4
PowerShell: 7.4.0
OS: Microsoft Windows 10.0.22621
BufferWidth: 169
BufferHeight: 41

Last 114 Keys:

 S e t - P S R e a d L i n e O p t i o n Spacebar - E d i t M o d e Spacebar V i Enter S e t - P S R e a d L i n e K e y H a n d l e r Spacebar - K e y Spacebar E n t e r Spacebar - F u n c t i o n Spacebar V a l i d a t e A n d A c c e p t L i n e Enter n o t v a l i d Enter Escape d d

### Exception

System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at System.Text.StringBuilder.get_Chars(Int32 index)
   at Microsoft.PowerShell.PSConsoleReadLine.ConvertOffsetToPoint(Int32 offset)
   at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
   at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
   at Microsoft.PowerShell.PSConsoleReadLine.RenderWithPredictionQueryPaused()
   at Microsoft.PowerShell.PSConsoleReadLine.ClearStatusMessage(Boolean render)
   at Microsoft.PowerShell.PSConsoleReadLine.SaveEditItem(EditItem editItem)
   at Microsoft.PowerShell.PSConsoleReadLine.DeleteLineImpl(Int32 lineIndex, Int32 lineCount)
   at Microsoft.PowerShell.PSConsoleReadLine.DeleteLine(Nullable`1 key, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(PSKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.ViChordHandler(Dictionary`2 secondKeyDispatchTable, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.ViChord(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

screenshot

Environment data
PS Version: 7.4.0
PS HostName: ConsoleHost (Windows Terminal)
PSReadLine Version: 2.3.4
PSReadLine EditMode: Vi
OS: 10.0.22621.2428 (WinBuild.160101.0800)
BufferWidth: 169
BufferHeight: 41
Steps to reproduce

Start pwsh without profile, set edit mode to Vi, set Enter key handler to ValidateAndAcceptLine, enter a not valid command, press Escape to exit insert mode, enter dd

Expected behavior

The current input is deleted

Actual behavior

The above exception happens

Dominant language
C#
Stars
4.4k
Forks
341
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PowerShell/PSReadLine

All issues in PowerShell/PSReadLine

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.