aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0385-Strip-private-area-unicode-characters-from-signs.patch
blob: 7e694e4f5875d48ecd4772d5fa0d262c809c5de6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
From 9cf28103bd677d93deb8ea8a0adf3c095a6e3b73 Mon Sep 17 00:00:00 2001
From: Zach Brown <zach@zachbr.io>
Date: Tue, 23 Oct 2018 20:53:43 -0400
Subject: [PATCH] Strip private area unicode characters from signs

It is not immediately clear how these characters ended up on signs in
previous versions. It is clear, however, that they now render as empty
unicode boxes in 1.13, whereas previously they rendered as invisible
characters.

When these signs are loaded in versions after this commit, these
characters from the private use area of the Unicode block will be
stripped. The sign will then be marked to ensure this conversion only
runs once.

There is a flag -DPaper.keepInvalidUnicode=true that can be used if you
do not want us to strip these characters from your signs, though I can
think of no reason to use it.

Fixes GH-1571

diff --git a/src/main/java/net/minecraft/server/TileEntitySign.java b/src/main/java/net/minecraft/server/TileEntitySign.java
index 458d1561d0..c2bcbbbab9 100644
--- a/src/main/java/net/minecraft/server/TileEntitySign.java
+++ b/src/main/java/net/minecraft/server/TileEntitySign.java
@@ -11,6 +11,11 @@ public class TileEntitySign extends TileEntity implements ICommandListener {
     private EntityHuman g;
     private final String[] h = new String[4];
 
+    // Paper start - Strip invalid unicode from signs on load
+    private static final boolean keepInvalidUnicode = Boolean.getBoolean("Paper.keepInvalidUnicode"); // Allow people to keep their bad unicode if they really want it
+    private boolean privateUnicodeRemoved = false;
+    // Paper end
+
     public TileEntitySign() {
         super(TileEntityTypes.SIGN);
     }
@@ -30,6 +35,12 @@ public class TileEntitySign extends TileEntity implements ICommandListener {
         }
         // CraftBukkit end
 
+        // Paper start - Only remove private area unicode once
+        if (this.privateUnicodeRemoved) {
+            nbttagcompound.setBoolean("Paper.RemovedPrivateUnicode", true);
+        }
+        // Paper end
+
         return nbttagcompound;
     }
 
@@ -37,6 +48,11 @@ public class TileEntitySign extends TileEntity implements ICommandListener {
         this.isEditable = false;
         super.load(nbttagcompound);
 
+        // Paper start - Keep track, only do it once per sign
+        this.privateUnicodeRemoved = nbttagcompound.getBoolean("Paper.RemovedPrivateUnicode");
+        boolean ranUnicodeRemoval = false;
+        // Paper end
+
         // CraftBukkit start - Add an option to convert signs correctly
         // This is done with a flag instead of all the time because
         // we have no way to tell whether a sign is from 1.7.10 or 1.8
@@ -49,6 +65,19 @@ public class TileEntitySign extends TileEntity implements ICommandListener {
                 s = "\"\"";
             }
 
+            // Paper start - Strip private use area unicode from signs
+            if (s != null && !keepInvalidUnicode && !this.privateUnicodeRemoved) {
+                StringBuilder builder = new StringBuilder();
+                for (char character : s.toCharArray()) {
+                    if (Character.UnicodeBlock.of(character) != Character.UnicodeBlock.PRIVATE_USE_AREA) {
+                        builder.append(character);
+                    }
+                }
+                s = builder.toString();
+                ranUnicodeRemoval = true;
+            }
+            // Paper end
+
             try {
                 //IChatBaseComponent ichatbasecomponent = IChatBaseComponent.ChatSerializer.a(s); // Paper - move down - the old format might throw a json error
 
@@ -75,6 +104,7 @@ public class TileEntitySign extends TileEntity implements ICommandListener {
             this.h[i] = null;
         }
 
+        if (ranUnicodeRemoval) this.privateUnicodeRemoved = true; // Paper - Flag to write NBT
     }
 
     public void a(int i, IChatBaseComponent ichatbasecomponent) {
-- 
2.21.0