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

PSException when using an emoji as string in command line #3691

Closed
3 tasks done
srirajshukla opened this issue May 17, 2023 · 4 comments
Closed
3 tasks done

PSException when using an emoji as string in command line #3691

srirajshukla opened this issue May 17, 2023 · 4 comments
Labels
Issue-Emoji Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.

Comments

@srirajshukla
Copy link

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.1.0
PowerShell: 7.2.11
OS: Microsoft Windows 10.0.19045
BufferWidth: 140
BufferHeight: 20

Last 200 Keys

 h e c k o u t Spacebar m e m Backspace l l o w Enter u g i t Spacebar k Enter u g i t Spacebar c o m m RightArrow Enter u g i t Spacebar k 
Enter u g i t Spacebar s t a t u s Enter u g i t Spacebar b r a n c h Spacebar b 2 Enter u g i t Spacebar k Enter u g i t Spacebar c h e c k o u t Spacebar b 2 Enter u g i t Spacebar Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace " i n Spacebar b r a n c h Spacebar b 2 " > Spacebar i n f o 2 2 . t x t Enter u g i t Spacebar o c m m Backspace Backspace Backspace Backspace c o m m i t Spacebar RightArrow LeftArrow Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace l o v e l y Enter UpArrow RightArrow RightArrow RightArrow RightArrow RightArrow RightArrow RightArrow RightArrow RightArrow RightArrow RightArrow RightArrow RightArrow RightArrow RightArrow RightArrow RightArrow RightArrow RightArrow RightArrow RightArrow RightArrow � RightArrow Enter

Exception

System.Text.EncoderFallbackException: Unable to translate Unicode character \\uD83D at index 22 to specified code page.
   at System.Text.EncoderExceptionFallbackBuffer.Fallback(Char charUnknown, Int32 index)
   at System.Text.EncoderFallbackBuffer.InternalFallback(ReadOnlySpan`1 chars, Int32& charsConsumed)
   at System.Text.Encoding.GetBytesWithFallback(ReadOnlySpan`1 chars, Int32 originalCharsLength, Span`1 bytes, Int32 originalBytesLength, EncoderNLS encoder)
   at System.Text.Encoding.GetBytesWithFallback(Char* pOriginalChars, Int32 originalCharCount, Byte* pOriginalBytes, Int32 originalByteCount, Int32 charsConsumedSoFar, Int32 bytesWrittenSoFar, EncoderNLS encoder)
   at System.Text.Encoding.GetBytes(Char* pChars, Int32 charCount, Byte* pBytes, Int32 byteCount, 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__DisplayClass83_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.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)


### Screenshot

N/A

### Environment data

```console
PS Version: 7.2.11
PS HostName: ConsoleHost
PSReadLine Version: 2.1.0
PSReadLine EditMode: Windows
OS: 10.0.19041.1 (WinBuild.160101.0800)
BufferWidth: 113
BufferHeight: 20

Steps to reproduce

"😊"

Expected behavior

The emoji should be printed.

Actual behavior

The above exception occurs

@ghost ghost added the Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. label May 17, 2023
@StevenBucher98
Copy link
Collaborator

Can you provide better reproduction steps? I can copy that emoji into my terminal just fine in the latest PSReadLine version. Can you upgrade to 2.2.6 and see if it still is happening?

@ListsOfArrays
Copy link

ListsOfArrays commented Jun 11, 2023

It's happening for me in 2.2.6 in the VS Code window.
When using the terminal page in VS Code, and using the Windows Emoji keyboard to insert an emoji (such as 🏆), the above exception occurs.

$test=[char]'🏆'

I cannot repro this on Windows Terminal though. Notably the emoji does not even show up correctly in VS Code.

@StevenBucher98
Copy link
Collaborator

@ListsOfArrays are you using the PowerShell VSCode extension? I was able to use both pwsh terminal and PowerShell Extension terminal to print an emoji in a string.

Also the code you provided seems to fail for me with the following
InvalidArgument: Cannot convert value "🏆" to type "System.Char". Error: "String must be exactly one character long."

I am not entirely sure what is underlying technology for emojis and ASCII char so this could be expected? cc @daxian-dbw in case he may know.

Also cc @andschwa for VSCode extension visibility.

@daxian-dbw
Copy link
Member

This is a duplicate of #2358

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. label Aug 7, 2023
@daxian-dbw daxian-dbw added the Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing. label Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Emoji Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.
Projects
None yet
Development

No branches or pull requests

4 participants