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

Fix an 'IndexOutOfRangeException' when error prompt contains CJK #1206

Merged
merged 1 commit into from
Nov 26, 2019

Conversation

daxian-dbw
Copy link
Member

The line promptText = promptText.Substring(promptText.Length - promptBufferCells); causes the index out-of-range exception because promptBufferCells might be larger than the length of the prompt text when it contains CJK characters.
This line doesn't make sense after a series of changes to the prompt rendering code and should be removed.

PS E:\pscore-test> Set-PSReadLineOption -PromptText "你好吗你?"
PS E:\pscore-test>
PS E:\pscore-test> i
Oops, something went wrong.  Please report this bug with the details below.
Report on GitHub: https://github.com/PowerShell/PSReadLine/issues/new
### Environment
PSReadLine: 2.0.0-beta5
PowerShell: 7.0.0-preview.5
OS: Microsoft Windows 10.0.18363
Last 21 Keys

"""
 Enter
 f a Backspace Backspace Backspace Ctrl+r s e t ` Escape Enter
 Enter
 f a Backspace Backspace Backspace i f
"""

### Exception

System.ArgumentOutOfRangeException: StartIndex cannot be less than zero. (Parameter 'startIndex')
   at System.String.Substring(Int32 startIndex, Int32 length)
   at System.String.Substring(Int32 startIndex)
   at Microsoft.PowerShell.PSConsoleReadLine.RenderErrorPrompt(RenderData renderData, String defaultColor)
   at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
   at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
   at Microsoft.PowerShell.PSConsoleReadLine.Render()
   at Microsoft.PowerShell.PSConsoleReadLine.Insert(Char c)
   at Microsoft.PowerShell.PSConsoleReadLine.SelfInsert(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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants