Fix quoted strings being parsed as booleans

This commit is contained in:
SPGoding 2019-07-24 20:28:50 +08:00
parent 559d8f3972
commit 2fb712212a
No known key found for this signature in database
GPG key ID: FBB825753D448705
2 changed files with 13 additions and 1 deletions

View file

@ -233,7 +233,7 @@ public class StringReader implements ImmutableStringReader {
public boolean readBoolean() throws CommandSyntaxException { public boolean readBoolean() throws CommandSyntaxException {
final int start = cursor; final int start = cursor;
final String value = readString(); final String value = readUnquotedString();
if (value.isEmpty()) { if (value.isEmpty()) {
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerExpectedBool().createWithContext(this); throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerExpectedBool().createWithContext(this);
} }

View file

@ -585,4 +585,16 @@ public class StringReaderTest {
assertThat(ex.getCursor(), is(0)); 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));
}
}
} }