From 2fb712212a0dd831e2068c0f1bcd383ea798ad2d Mon Sep 17 00:00:00 2001 From: SPGoding Date: Wed, 24 Jul 2019 20:28:50 +0800 Subject: [PATCH] Fix quoted strings being parsed as booleans --- src/main/java/com/mojang/brigadier/StringReader.java | 2 +- .../java/com/mojang/brigadier/StringReaderTest.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/mojang/brigadier/StringReader.java b/src/main/java/com/mojang/brigadier/StringReader.java index c1465df..da5c378 100644 --- a/src/main/java/com/mojang/brigadier/StringReader.java +++ b/src/main/java/com/mojang/brigadier/StringReader.java @@ -233,7 +233,7 @@ public class StringReader implements ImmutableStringReader { public boolean readBoolean() throws CommandSyntaxException { final int start = cursor; - final String value = readString(); + final String value = readUnquotedString(); if (value.isEmpty()) { throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerExpectedBool().createWithContext(this); } diff --git a/src/test/java/com/mojang/brigadier/StringReaderTest.java b/src/test/java/com/mojang/brigadier/StringReaderTest.java index 23e2c14..7c06ad9 100644 --- a/src/test/java/com/mojang/brigadier/StringReaderTest.java +++ b/src/test/java/com/mojang/brigadier/StringReaderTest.java @@ -585,4 +585,16 @@ public class StringReaderTest { assertThat(ex.getCursor(), is(0)); } } + + @Test + public void readBoolean_quoted() throws Exception { + final StringReader reader = new StringReader("\"true\""); + try { + reader.readBoolean(); + fail(); + } catch (final CommandSyntaxException ex) { + assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerExpectedBool())); + assertThat(ex.getCursor(), is(0)); + } + } } \ No newline at end of file