Skip to content

TextField crashes app when pasting unicode surrogate pair #3966

Closed
@tznind

Description

@tznind

Describe the bug
When pasting a 2 char pair e.g. 📄 the TextField crashes with following exception:

System.ArgumentOutOfRangeException
Specified argument was out of the range of valid values. (Parameter 'value')
   at System.Text.Rune..ctor(UInt32 value)
   at Terminal.Gui.Key.ToRune(KeyCode key) in D:\Repos\temp\gui.cs\Terminal.Gui\Input\Keyboard\Key.cs:line 349
   at Terminal.Gui.Key.get_AsRune() in D:\Repos\temp\gui.cs\Terminal.Gui\Input\Keyboard\Key.cs:line 156
   at Terminal.Gui.TextField.InsertText(Key a, Boolean usePreTextChangedCursorPos) in D:\Repos\temp\gui.cs\Terminal.Gui\Views\TextField.cs:line 1389
   at Terminal.Gui.TextField.InsertText(String toAdd, Boolean useOldCursorPos) in D:\Repos\temp\gui.cs\Terminal.Gui\Views\TextField.cs:line 750
   at Terminal.Gui.ViewsTests.TextFieldTests.TestPasteUnicodeTextField() in D:\Repos\temp\gui.cs\Tests\UnitTests\Views\TextFieldTests.cs:line 1982
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

To Reproduce
Steps to reproduce the behavior:

    [Fact]
    public void TestPasteUnicodeTextField ()
    {
        var tf = new TextField ();
        //📄
        tf.InsertText ("\ud83d\udcc4");

    }

Expected behavior
If it is not supported by Terminal.Gui then ignore the paste i.e. paste nothing

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Status

    ✅ Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions