`KillRegion` function raises an unhandled exception on empty region

Aperta Adatta ai principianti
#5,045 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
64/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
csharp
Ambito
cli

Direzione di ricerca

Inizia riproducendo il problema con i binding documentati di KillRegion e SetMark, quindi segui lo stack trace da KillRegion a Kill. Conferma che il caso di una regione vuota attualmente solleva un’eccezione. Il lavoro è completato quando ripetere KillRegion su una regione vuota restituisce un ding senza sollevare un’eccezione non gestita.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Needs-Triage :mag:
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.4.5
PowerShell: 7.6.0-preview.5
OS: Microsoft Windows 10.0.26100
BufferWidth: 120
BufferHeight: 9001

Last 200 Keys:

 d l i n e o p Tab Tab Spacebar Spacebar Backspace - Tab Tab Tab Tab Tab Tab Tab Tab Tab Tab Tab Tab Tab Tab Tab Tab Tab Tab Tab Tab Tab Tab Tab Tab Shift+Tab Spacebar Tab Tab Tab Enter
 d f d f Backspace Backspace Backspace Backspace s e t - p s r e a d l i n e k e y h a n d l e r Spacebar c Backspace - c h o r t Tab Backspace d Tab Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace n o t e p a d Spacebar . \ p r o f i l e . p s q Backspace 1 Enter
 . Spacebar p r o Tab Enter
 t h i s Spacebar i d Spacebar a Spacebar d Backspace Backspace Backspace Backspace Backspace s Spacebar a Spacebar d e b a Backspace u g Spacebar t e s t LeftArrow LeftArrow LeftArrow LeftArrow LeftArrow Ctrl+a LeftArrow LeftArrow LeftArrow LeftArrow LeftArrow LeftArrow LeftArrow LeftArrow Ctrl+b Ctrl+b

### Exception

System.ArgumentOutOfRangeException: Index and length must refer to a location within the string. (Parameter 'length')
   at System.Text.StringBuilder.ToString(Int32 startIndex, Int32 length)
   at Microsoft.PowerShell.PSConsoleReadLine.Kill(Int32 start, Int32 length, Boolean prepend)
   at Microsoft.PowerShell.PSConsoleReadLine.KillRegion(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
Image
Environment data
PS Version: 7.6.0-preview.5
PS HostName: ConsoleHost (Windows Terminal)
PSReadLine Version: 2.4.5
PSReadLine EditMode: Windows
OS: 10.0.26100.1 (WinBuild.160101.0800)
BufferWidth: 120
BufferHeight: 9001
Steps to reproduce
  1. Bind both the KillRegion and SetMark functions to a chord each (this is what profile.ps1 does in the example above)
  2. Set a mark with `SetMark anywhere on the line, except on the first column
  3. Move the cursor before the mark
  4. Kill the region of text between the cursor and the mark with KillRegion
  5. Try to kill the region again
Expected behavior

Since the region is empty and thus cannot be killed, the function should return a ding.

Actual behavior

An unhandled exception is raised.

Lingua principale
C#
Stelle
4.4k
Fork
341
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di PowerShell/PSReadLine

Tutte le issue di PowerShell/PSReadLine

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.