Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-265927

Edit box length restrictions can result in unpaired surrogate characters

XMLWordPrintable

    • Confirmed
    • Input, UI
    • Normal
    • Platform

      The length restriction on edit boxes can result in unpaired surrogate characters.

      Reproduction

      1. Open the world creation screen.
      2. Paste a𐑐𐑐𐑐𐑐𐑐𐑐𐑐𐑐𐑐𐑐𐑐𐑐𐑐𐑐𐑐𐑐𐑐𐑐𐑐 (an ‘a’ followed by repeated U+10450 characters) into the world name box

      Intended behavior: The text contents cut off after one of the U+10450s.
      Actual behavior: The contents end with an unpaired surrogate character.

      Code analysis

      (For the 1.20.2 code, using Yarn version 1.20.2+build.1.)

      • TextFieldWidget#setText truncates the string to maxLength UTF-16 code units, without regard to whether doing so would split the text in the middle of a surrogate pair.
      • Similarly, TextFieldWidget#write truncates the string inserted so that the new text is at most maxLength code units long, whether or not doing so would split a surrogate pair.

            Karaoglu [Mojang] eowyn36
            fluffy8x +merlan #flirora
            Votes:
            3 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: