Skip to content

Commit

Permalink
Merge pull request #452 from kennytv/fix/trailing-comma
Browse files Browse the repository at this point in the history
  • Loading branch information
zml2008 committed Sep 25, 2021
2 parents 4877bb3 + 96aad41 commit c324532
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ private boolean separatorOrCompleteWith(final char endCharacter) throws StringTa
return true;
}
this.buffer.expect(Tokens.VALUE_SEPARATOR);
return false;
return this.buffer.takeIf(endCharacter);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions nbt/src/test/java/net/kyori/adventure/nbt/StringIOTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ void testEmptyLongArray() throws IOException {
assertEquals(LongArrayBinaryTag.of(), this.stringToTag("[L; ]"));
}

@Test
void testTrailingComma() throws IOException {
assertEquals(CompoundBinaryTag.builder().putString("test", "hello").build(), this.stringToTag("{test: \"hello\",}"));
assertEquals(IntArrayBinaryTag.of(1), this.stringToTag("[I;1,]"));
assertEquals(ListBinaryTag.builder().add(StringBinaryTag.of("hello")).build(), this.stringToTag("[\"hello\",]"));
}

private String tagToString(final BinaryTag tag) throws IOException {
final StringWriter writer = new StringWriter();
try(final TagStringWriter emitter = new TagStringWriter(writer, "")) {
Expand Down

0 comments on commit c324532

Please sign in to comment.