PrettyPrompt icon indicating copy to clipboard operation
PrettyPrompt copied to clipboard

Pasting ๐Ÿคฆ๐Ÿผโ€โ™‚๏ธcharacter into repl throws exception and exits repl

Open MikeSchurman opened this issue 2 years ago โ€ข 4 comments

Version

0.6.5

What happened?

I tried pasting the ๐Ÿคฆ๐Ÿผโ€โ™‚๏ธcharacter into the repl and it throws an exception:

image

> Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   at PrettyPrompt.Rendering.Screen.PositionCursor(Screen screen, ConsoleCoordinate cursor)
   at PrettyPrompt.Rendering.Screen..ctor(Int32 width, Int32 height, ConsoleCoordinate cursor, ScreenArea[] screenAreas) โ”‚
   at PrettyPrompt.Renderer.<RenderOutput>g__Redraw|7_0(<>c__DisplayClass7_0&)
   at PrettyPrompt.Renderer.RenderOutput(PromptResult result, CodePane codePane, OverloadPane overloadPane, CompletionPane completionPane, IReadOnlyCollection`1 highlights, KeyPress key)โ”‚ AppContext               โ”‚
   at PrettyPrompt.Prompt.RenderSyntaxHighlightedOutput(Renderer renderer, CodePane codePane, OverloadPane overloadPane, CompletionPane completionPane, KeyPress key, String inputText, PromptResult result)โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
   at PrettyPrompt.Prompt.ReadLineAsync()
   at CSharpRepl.ReadEvalPrintLoop.RunAsync(Configuration config) in D:\a\CSharpRepl\CSharpRepl\CSharpRepl\ReadEvalPrintLoop.cs:line 49
   at CSharpRepl.Program.Main(String[] args) in D:\a\CSharpRepl\CSharpRepl\CSharpRepl\Program.cs:line 68
   at CSharpRepl.Program.Main(String[] args) in D:\a\CSharpRepl\CSharpRepl\CSharpRepl\Program.cs:line 74
   at CSharpRepl.Program.<Main>(String[] args)

MikeSchurman avatar Oct 02 '23 13:10 MikeSchurman

Thanks for reporting this! It was definitely working before, and I thought we even had good integration tests around this. I'll see what happened.

waf avatar Oct 03 '23 02:10 waf

Just a note for myself, ๐Ÿคฆ๐Ÿผโ€โ™‚๏ธ is composed of the following codepoints:

Render Codepoint Name
๐Ÿคฆ U+1F926 FACE PALM
๐Ÿผ U+1F3FC EMOJI MODIFIER FITZPATRICK TYPE-3
โ€ U+200D ZERO WIDTH JOINER
โ™‚ U+2642 MALE SIGN
U+FE0F VARIATION SELECTOR-16

I'm transferring this to the PrettyPrompt underlying library repository where it should be fixed.

waf avatar Nov 17 '23 13:11 waf

  • โš ๏ธ (U+26A0 U+FE0F) โ†’ No crash
  • ๐Ÿคฆ (U+1F926) โ†’ No crash
  • ๐Ÿคฆ๐Ÿผ (U+1F926 U+1F3FC) โ†’ CRASH
  • ๐Ÿคฆโ€โ™‚ (U+1F926 U+200D U+2642) โ†’ CRASH
  • ๐Ÿคฆ๏ธ๏ธ (U+1F926 U+FE0F) โ†’ No crash
  • ๐ ฎŸ (U+20B9F; means "scold") โ†’ No crash
  • ็ฆฐ (U+79B0) โ†’ No crash
  • ็ฆฐ๓ „€ (U+79B0 U+E0100; used in the name of the sister of the main character of Daemon Slayer: Kimetsu no Yaiba) โ†’ CRASH
  • ไพฎ๏ธ€ (U+4FAE U+FE00) โ†’ No crash
  • ๐Ÿ‘ฉโ€๐Ÿ’ป (U+1F469 U+200D U+1F4BB) โ†’ No crash but not joinned

tats-u avatar Jan 20 '24 09:01 tats-u

https://github.com/waf/PrettyPrompt/blob/4245c197b21500a634d9fbe29cad0e9d5f4753cc/src/PrettyPrompt/Rendering/Screen.cs#L100

This assertion fails.

https://github.com/waf/PrettyPrompt/blob/4245c197b21500a634d9fbe29cad0e9d5f4753cc/src/PrettyPrompt/Rendering/UnicodeWidth.cs#L244

This returns more than two and the returned value is set to .ElementWidth.

UnicodeWidth does not consider ๐Ÿ‚ก๐Ÿ‚ข๐Ÿ‚ฃ or ๐Ÿ€€๐Ÿ€, which are in the SMP (not BMP) and whose width should be treated as 1.

No Rune available only in .NET is used there. We can use StringInfo.GetTextElementEnumerator to split string into grapheme clusters now.

tats-u avatar Jan 23 '24 16:01 tats-u