PSReadLine icon indicating copy to clipboard operation
PSReadLine copied to clipboard

Enumeration of String with illegal characters results in exception

Open drandarov-io opened this issue 1 year ago • 0 comments

Prerequisites

  • [X] Write a descriptive title.
  • [X] Make sure you are able to repro it on the latest released version
  • [X] Search the existing issues, especially the pinned issues.

Exception report

"asasfs�".GetEnumerator()

Oops, something went wrong.
Please report this bug with ALL the details below, including both the 'Environment' and 'Exception' sections.
Please report on GitHub: https://github.com/PowerShell/PSReadLine/issues/new?template=Bug_Report.yaml
Thank you!

### Environment
PSReadLine: 2.3.5+2cc85806c561a9395751a96a818e8ff1592d19f7
PowerShell: 7.4.3
OS: Microsoft Windows 10.0.26100
BufferWidth: 160
BufferHeight: 45

Last 55 Keys:

 � � Enter
 UpArrow Home e c h o Spacebar Enter
 UpArrow Ctrl+LeftArrow Ctrl+Backspace " Shift+End " Ctrl+z End " Enter
 UpArrow . G e t Tab RightArrow RightArrow RightArrow Enter
 ) Enter
 UpArrow Ctrl+Backspace G e t E n Tab ) Enter
 UpArrow Insert Home RightArrow Delete a s a s f s Enter


### Exception

System.Text.EncoderFallbackException: Unable to translate Unicode character \\uDD23 at index 7 to specified code page.
   at System.Text.EncoderExceptionFallbackBuffer.Fallback(Char charUnknown, Int32 index)
   at System.Text.Encoding.GetBytesWithFallback(ReadOnlySpan`1 chars, Int32 originalCharsLength, Span`1 bytes, Int32 originalBytesLength, EncoderNLS encoder, Boolean throwForDestinationOverflow)
   at System.Text.Encoding.GetBytesWithFallback(Char* pOriginalChars, Int32 originalCharCount, Byte* pOriginalBytes, Int32 originalByteCount, Int32 charsConsumedSoFar, Int32 bytesWrittenSoFar, EncoderNLS encoder)
   at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
   at System.IO.StreamWriter.Dispose(Boolean disposing)
   at System.IO.TextWriter.Dispose()
   at Microsoft.PowerShell.PSConsoleReadLine.<>c__DisplayClass103_0.<WriteHistoryRange>b__0()
   at Microsoft.PowerShell.PSConsoleReadLine.WithHistoryFileMutexDo(Int32 timeout, Action action)
   at Microsoft.PowerShell.PSConsoleReadLine.WriteHistoryRange(Int32 start, Int32 end, Boolean overwritten)
   at Microsoft.PowerShell.PSConsoleReadLine.IncrementalHistoryWrite()
   at Microsoft.PowerShell.PSConsoleReadLine.MaybeAddToHistory(String result, List`1 edits, Int32 undoEditIndex, Boolean fromDifferentSession, Boolean fromInitialRead)
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken, Nullable`1 lastRunStatus)

Screenshot

image

Environment data

PowerShell 7.4.3
PSReadLine 2.3.5
Windows 11

Steps to reproduce

Delete the first character of the string "🤣". Then use resulting string "�" Note: Copy pasting the character from GitHub does not reproduce this issue. Only editing the emoji inside the terminal results in the exception-causing string.

Expected behavior

No exception when using string.

Actual behavior

Exception when using string.

drandarov-io avatar Jul 10 '24 12:07 drandarov-io