diff --git a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java index c2619a5fc8..4b2f7a0508 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java +++ b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java @@ -403,7 +403,10 @@ public class CraftBlockData implements BlockData { data = Block.REGISTRY.b(block) + data; } - ArgumentBlock arg = new ArgumentBlock(new StringReader(data), false).a(false); + StringReader reader = new StringReader(data); + ArgumentBlock arg = new ArgumentBlock(reader, false).a(false); + Preconditions.checkArgument(!reader.canRead(), "Spurious trailing data"); + blockData = arg.b(); } catch (CommandSyntaxException ex) { throw new IllegalArgumentException("Could not parse data: " + data, ex); diff --git a/src/test/java/org/bukkit/BlockDataTest.java b/src/test/java/org/bukkit/BlockDataTest.java index a5cea50bec..bd2c249b3b 100644 --- a/src/test/java/org/bukkit/BlockDataTest.java +++ b/src/test/java/org/bukkit/BlockDataTest.java @@ -44,6 +44,13 @@ public class BlockDataTest extends AbstractTestingBase { CraftBlockData.newData(Material.CAKE, "minecraft:cake[bites=3]"); } + @Test(expected = IllegalArgumentException.class) + public void testMistake() { + BlockData cakeTest = CraftBlockData.fromData(Blocks.CAKE.getBlockData().set(BlockCake.BITES, 3)); + + CraftBlockData.newData(Material.CAKE, cakeTest.toString()); + } + @Test public void testClone() { Cake cakeTest = (Cake) CraftBlockData.fromData(Blocks.CAKE.getBlockData().set(BlockCake.BITES, 3));