Skip to content

Commit

Permalink
Merge pull request #1108 from 456dev/fix/gson-decode-number
Browse files Browse the repository at this point in the history
ensure numbers where we expected booleans parse correctly.
  • Loading branch information
zml2008 authored Dec 8, 2024
2 parents 18a9e9f + 4d0cb74 commit 97b1abe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
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 @@ -35,7 +35,6 @@
import net.kyori.adventure.text.format.TextDecoration;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -95,7 +94,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

0 comments on commit 97b1abe

Please sign in to comment.