Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure numbers where we expected booleans parse correctly. #1108

Open
wants to merge 2 commits into
base: main/4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ static boolean readBoolean(final JsonReader in) throws IOException {
final JsonToken peek = in.peek();
if (peek == JsonToken.BOOLEAN) {
return in.nextBoolean();
} else if (peek == JsonToken.STRING || peek == JsonToken.NUMBER) {
} else if (peek == JsonToken.STRING) {
return Boolean.parseBoolean(in.nextString());
} else if (peek == JsonToken.NUMBER) {
return in.nextString().equals("1");
} else {
throw new JsonParseException("Token of type " + peek + " cannot be interpreted as a boolean");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void testDecoration() {
object.addProperty(JSONComponentConstants.TEXT, "");
object.addProperty(name(TextDecoration.BOLD), 1);
})).style();
assertFalse(s0.hasDecoration(TextDecoration.BOLD));
assertTrue(s0.hasDecoration(TextDecoration.BOLD));

assertThrows(RuntimeException.class, () -> {
deserialize(object(object -> {
Expand Down
Loading