From 57561c859f440391abc2c8df0beda1e7545cbcb3 Mon Sep 17 00:00:00 2001 From: ktlo Date: Tue, 28 Sep 2021 16:08:55 +0000 Subject: [PATCH] Fix issue #2 on GitHub --- .vscode/settings.json | 4 +++- include/nbt.hpp | 6 ++++++ test/issue2.cpp | 17 +++++++++++++++++ test/meson.build | 3 ++- 4 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 test/issue2.cpp diff --git a/.vscode/settings.json b/.vscode/settings.json index 7312a38..da37764 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -43,6 +43,8 @@ "stdexcept": "cpp", "streambuf": "cpp", "typeinfo": "cpp", - "config.cpp.in": "cpp" + "config.cpp.in": "cpp", + "cinttypes": "cpp", + "map": "cpp" } } \ No newline at end of file diff --git a/include/nbt.hpp b/include/nbt.hpp index 306369c..f81d31e 100644 --- a/include/nbt.hpp +++ b/include/nbt.hpp @@ -217,6 +217,12 @@ template std::vector load_array_text(std::istream & input) { std::vector result; for (;;) { + skip_space(input); + char c = cheof(input); + input.putback(c); + if (c == ']') { + break; + } result.push_back(load_text(input)); skip_space(input); char next = cheof(input); diff --git a/test/issue2.cpp b/test/issue2.cpp new file mode 100644 index 0000000..35b6b06 --- /dev/null +++ b/test/issue2.cpp @@ -0,0 +1,17 @@ +#include + +#include "nbt.hpp" + +#include "test.hpp" + +using namespace nbt; + +test { + std::stringstream input(R"({ "voidByteArray": [B; ] })"); + tags::compound_tag root; + input >> contexts::mojangson >> root; + std::string key("voidByteArray"); + auto & bytes = root.get>(key); + assert_true(bytes.empty()); + std::cout << contexts::mojangson << root; +} diff --git a/test/meson.build b/test/meson.build index 7f4afe0..6761b5f 100644 --- a/test/meson.build +++ b/test/meson.build @@ -1,5 +1,6 @@ test_names = [ - 'nbt' + 'nbt', + 'issue2' ] test_files = []