Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexOutOfRange or ArgumentOutOfRange exception when using bck-i-search with a buffer height of 1 #4139

Open
3 tasks done
stefior opened this issue Aug 26, 2024 · 2 comments
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Triage 🔍 It's a new issue that core contributor team needs to triage.

Comments

@stefior
Copy link

stefior commented Aug 26, 2024

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.5+2cc85806c561a9395751a96a818e8ff1592d19f7
PowerShell: 7.4.5
OS: Microsoft Windows 10.0.19045
BufferWidth: 106
BufferHeight: 1

Last 1 Keys:

 Ctrl+r

### 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.Render()
   at Microsoft.PowerShell.PSConsoleReadLine.InteractiveHistorySearch(Int32 direction)
   at Microsoft.PowerShell.PSConsoleReadLine.ReverseSearchHistory(Nullable`1 key, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(PSKeyInfo key, Dictionary`2 dispatchTable, Bool
ean 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.5
PS HostName: ConsoleHost (Windows Terminal)
PSReadLine Version: 2.3.5
PSReadLine EditMode: Windows
OS: 10.0.19041.1 (WinBuild.160101.0800)
BufferWidth: 106
BufferHeight: 1

Steps to reproduce

Minimum reproducible example:

  1. Create a new pane in Windows Terminal
  2. Resize the pane to the minimum size
  3. Press Ctrl+r
  4. Press Enter

It could be a tab or pane with any amount of history (including no history). If using a tab instead of a pane, you'd just need to resize the whole window instead. After pressing Ctrl+r, it also doesn't make a difference what is typed before pressing enter. If, after pressing Ctrl+r, the pane is resized to not be the minimum, it will still have the same error.

If you press Ctrl+r first at a normal size, then resize to a height of 1, then press the Enter key, it will raise a different exception:

System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the cons
ole's buffer size in that dimension. (Parameter 'top')
Actual value was 2.
   at System.ConsolePal.SetCursorPosition(Int32 left, Int32 top)
   at Microsoft.PowerShell.Internal.VirtualTerminal.SetCursorPosition(Int32 left, Int32 top)
   at Microsoft.PowerShell.PSConsoleReadLine.CalculateWhereAndWhatToRender(Boolean cursorMovedToInitialPos
, RenderData renderData, LineInfoForRendering& lineInfoForRendering)
   at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
   at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
   at Microsoft.PowerShell.PSConsoleReadLine.Render()
   at Microsoft.PowerShell.PSConsoleReadLine.RenderWithPredictionQueryPaused()
   at Microsoft.PowerShell.PSConsoleReadLine.ClearStatusMessage(Boolean render)
   at Microsoft.PowerShell.PSConsoleReadLine.InteractiveHistorySearch(Int32 direction)
   at Microsoft.PowerShell.PSConsoleReadLine.ReverseSearchHistory(Nullable`1 key, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(PSKeyInfo key, Dictionary`2 dispatchTable, Bool
ean ignoreIfNoAction, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics
, CancellationToken cancellationToken, Nullable`1 lastRunStatus)

Expected behavior

I expect it to work like bck-i-search normally does.

Actual behavior

The above exception happens, and it doesn't search the command history either.
For example, if I open a new instance of PowerShell and type in test, then do Ctrl+r to initiate reverse i search, then type in t and press enter, it would normally say, "the term 'test' is not recognized ..." (as it should). If the buffer height is 1, it instead says, "the term 't' is not recognized ...".

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. label Aug 26, 2024
@StevenBucher98 StevenBucher98 added the Issue-Bug It either shouldn't be doing this or needs an investigation. label Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Triage 🔍 It's a new issue that core contributor team needs to triage.
Projects
None yet
Development

No branches or pull requests

4 participants
@StevenBucher98 @stefior and others