summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authormd_5 <git@md-5.net>2018-07-20 10:20:15 +1000
committermd_5 <git@md-5.net>2018-07-20 10:20:15 +1000
commit49ac8a74461de1c2571296e300de001a93e00c75 (patch)
treeaac0645901660ef9c95d135c39199491d62f7d82 /src
parentc1d9f942238443b0b3074b49e2c5f57700f8af3c (diff)
downloadcraftbukkit-49ac8a74461de1c2571296e300de001a93e00c75.tar
craftbukkit-49ac8a74461de1c2571296e300de001a93e00c75.tar.gz
craftbukkit-49ac8a74461de1c2571296e300de001a93e00c75.tar.lz
craftbukkit-49ac8a74461de1c2571296e300de001a93e00c75.tar.xz
craftbukkit-49ac8a74461de1c2571296e300de001a93e00c75.zip
SPIGOT-4074: Fix createBlockData succeeding on garbage
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java5
-rw-r--r--src/test/java/org/bukkit/BlockDataTest.java7
2 files changed, 11 insertions, 1 deletions
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 c2619a5f..4b2f7a05 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 a5cea50b..bd2c249b 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));