From 52215f035b34a0491036130cfbfa7a35ad682e3f Mon Sep 17 00:00:00 2001 From: root Date: Mon, 13 Jul 2026 11:38:56 -0400 Subject: [PATCH] Fix 1 verified bug(s) from deep review - [high] src/main/java/com/k33bz/postbox/Mailboxes.java: Player name not escaped in SNBT command string --- src/main/java/com/k33bz/postbox/Mailboxes.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/k33bz/postbox/Mailboxes.java b/src/main/java/com/k33bz/postbox/Mailboxes.java index 6bdc402..92d2f26 100644 --- a/src/main/java/com/k33bz/postbox/Mailboxes.java +++ b/src/main/java/com/k33bz/postbox/Mailboxes.java @@ -20,6 +20,11 @@ public final class Mailboxes { private Mailboxes() { } + /** Escape a string for safe interpolation inside an SNBT double-quoted string literal. */ + private static String escapeSnbtString(String s) { + return s.replace("\\", "\\\\").replace("\"", "\\\""); + } + /** Form a mailbox: head block at {@code headPos} was just placed on an end rod. */ public static Mail.Box form(ServerLevel level, ServerPlayer placer, BlockPos headPos) { BlockPos rod = headPos.below(); @@ -70,7 +75,7 @@ public static void spawnDisplays(ServerLevel level, Mail.Box box) { Mail.run(level, String.format(Locale.ROOT, "summon minecraft:text_display %.2f %.2f %.2f {Tags:[\"%s\",\"%s\"],billboard:\"center\"," + "see_through:1b,text:{text:\"%s's Mailbox\",color:\"gold\"}}", - cx, top + 0.95, cz, Mail.BOX_TAG, tag, box.ownerName)); + cx, top + 0.95, cz, Mail.BOX_TAG, tag, escapeSnbtString(box.ownerName))); // Interaction hitbox around the body Mail.run(level, String.format(Locale.ROOT, "summon minecraft:interaction %.2f %.2f %.2f {Tags:[\"%s\",\"%s\"],width:1.2f,height:0.8f}",