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

Unicode characters which are not converted 1:1 when calling toLowerCase result in wrong formatting

    Details

    • Type: Bug
    • Status: Resolved
    • Resolution: Fixed
    • Affects Version/s: Minecraft 1.11
    • Fix Version/s: Minecraft 16w50a
    • Labels:
      None
    • Confirmation Status:
      Confirmed

      Description

      The Turkish I thingy can strip color. In the commands below "Test" is white, not blue:

      /tellraw @p {"extra":[{"color":"red","text":"Testİng"},{"color":"blue","text":" Test"}],"text":""}
      /tellraw @p {"color":"red","text":"Testİng","extra":[{"color":"blue","text":" Test"}]}
      

      Code analysis

      This happens because the font renderer (net.minecraft.client.gui.FontRenderer.renderStringAtPos(String, boolean)) does the following if it finds a formatting character (§):

      1. Convert the string to lower case
      2. Get the character at index + 1 to determine which formatting should be applied

      The problem here is that the to lower case conversion does not always convert 1:1 but may also convert 1:2 or 1:3 (see also http://www.unicode.org/Public/UNIDATA/SpecialCasing.txt). One example for this is as described in this report the character İ which is converted to (2 characters). When the font renderer then tries to get the character determining the formatting it actually gets the formatting character itself because the string length increased.

      Luckily the case in which the string gets shortened, which could crash Minecraft, is only the case for certain locales and English (which the font renderer currently uses) is not one of them.

      This could probably be fixed by first getting the character at the index + 1 and then calling Character.toLowerCase(char). This way it would only "convert" invalid formatted texts to valid formatted texts, for example §İTest to §iTest (italic), which is probably not such a big problem.

        Attachments

          Activity

            People

            • Assignee:
              grum [Mojang] Grum (Erik Broes)
              Reporter:
              md_5 [Mod] md_5
            • Votes:
              2 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                CHK: