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

Fix reading of trailing comma in nbt list/array/compound #452

Merged
merged 1 commit into from
Sep 25, 2021
Merged
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 @@ -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