Mojira Archive
MC-94456

Chat converting NBSP (non-breaking space) to space causes glitches

When non-breaking space characters (U+00A0) are sent in chat, they are converted to space characters. However, spaces are cleaned up (removed at the beginning and end, etc.) before this conversion, meaning that NBSPs can be used to bypass it.

Examples: ("#" means a NBSP character)

  • a##########b##########c creates a lot of spaces between a, b, and c
  • #####abc creates a lot of spaces before the chat message "abc" (Since sometime between 17w06a and 17w15a, Minecraft now removes NBSPs at the beginning of the message)
  • # creates a "blank" chat message containing only a space

The cause

Decompiled via MCP 9.24 beta:

net.minecraft.network.NetHandlerPlayServer.processChatMessage(CPacketChatMessage)
    /**
     * Process chat messages (broadcast back to clients) and commands (executes)
     */
    public void processChatMessage(CPacketChatMessage packetIn)
    {
        // ...
        else
        {
            this.playerEntity.markPlayerActive();
            String s = packetIn.getMessage();
            s = StringUtils.normalizeSpace(s); // <- here
            // ...
        }
    }

net.minecraft.network.NetHandlerPlayServer.processChatMessage(CPacketChatMessage) calls org.apache.commons.lang3.StringUtils.normalizeSpace(String), which uses its WHITESPACE_PATTERN.

Mojang can fix this by first replacing all NBSP with spaces via s.replace('\u00A0', ' ') (though it is kind of hacky), or by using their own pattern instead of Apache's WHITESPACE_PATTERN.


Original description

Copy-pasting non-breaking space characters (or using Opt-Space on a Mac) into chat causes them to be converted into normal spaces when the chat message is sent. However, this can cause bugs as they can be stringed together to create multiple spaces in a row, something that is not possible with regular spaces. Also, this can be used to send "blank" chat messages (only a space).

A way to fix:

It seems to me that the game first changes all double-spaces to single space characters, then checks if the message is empty, and then converts non-breaking spaces to spaces.

To fix the issue, the game should first convert non-breaking spaces to spaces, then change double-spaces to single spaces and check if the message is empty.


Possibly not a minecraft bug, see this comment.