`KillRegion` function raises an unhandled exception on empty region

Abierto Apto para principiantes
#5,045 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
64/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
csharp
Área
cli

Línea de trabajo

Empieza reproduciendo el problema con los bindings documentados de KillRegion y SetMark, y sigue después el stack trace desde KillRegion hasta Kill. Confirma que el caso de una región vacía actualmente provoca una excepción. Se considera terminado cuando repetir KillRegion sobre una región vacía devuelve un ding sin producir una excepción no controlada.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
C#
Estrellas
4.4k
Forks
341
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de PowerShell/PSReadLine

Todos los issues de PowerShell/PSReadLine

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.