From 2daab5a4c24daa447a9d636b5c62121933fb84f1 Mon Sep 17 00:00:00 2001 From: Niels Date: Sun, 11 Sep 2016 22:30:08 +0200 Subject: [PATCH] fixed #306 --- README.md | 2 +- src/json.hpp | 2 +- src/json.hpp.re2c | 2 +- test/data/regression/broken_file.json | 1 + test/data/regression/working_file.json | 1 + test/src/unit-regression.cpp | 17 +++++++++++++++++ 6 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 test/data/regression/broken_file.json create mode 100644 test/data/regression/working_file.json diff --git a/README.md b/README.md index 1c62e1374..63b629002 100644 --- a/README.md +++ b/README.md @@ -512,7 +512,7 @@ To compile and run the tests, you need to execute $ make check =============================================================================== -All tests passed (8905154 assertions in 35 test cases) +All tests passed (8905158 assertions in 35 test cases) ``` For more information, have a look at the file [.travis.yml](https://github.com/nlohmann/json/blob/master/.travis.yml). diff --git a/src/json.hpp b/src/json.hpp index 25a9dbcf7..a428d6f80 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -8592,7 +8592,7 @@ basic_json_parser_63: const auto offset_cursor = m_cursor - m_start; // no stream is used or end of file is reached - if (m_stream == nullptr or not * m_stream) + if (m_stream == nullptr or m_stream->eof()) { // copy unprocessed characters to line buffer m_line_buffer.clear(); diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 7ca046eaf..e5688e3e5 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -7889,7 +7889,7 @@ class basic_json const auto offset_cursor = m_cursor - m_start; // no stream is used or end of file is reached - if (m_stream == nullptr or not * m_stream) + if (m_stream == nullptr or m_stream->eof()) { // copy unprocessed characters to line buffer m_line_buffer.clear(); diff --git a/test/data/regression/broken_file.json b/test/data/regression/broken_file.json new file mode 100644 index 000000000..622d51ede --- /dev/null +++ b/test/data/regression/broken_file.json @@ -0,0 +1 @@ +{"AmbientOcclusion":false,"AnisotropicFiltering":16,"FOV":90,"FullScreen":true,"MipmapLevel":4,"RenderDistance":4,"VSync":true,"WindowResX":1920,"WindowResY":1080} \ No newline at end of file diff --git a/test/data/regression/working_file.json b/test/data/regression/working_file.json new file mode 100644 index 000000000..87436c205 --- /dev/null +++ b/test/data/regression/working_file.json @@ -0,0 +1 @@ +{"AmbientOcclusion":false,"AnisotropicFiltering":16,"FOV":90,"FullScreen":true,"MipmapLevel":4,"RenderDistance":4,"VSync":true,"WindowResX":1920,"WindowResY":1080} \ No newline at end of file diff --git a/test/src/unit-regression.cpp b/test/src/unit-regression.cpp index f61595a90..ed432e585 100644 --- a/test/src/unit-regression.cpp +++ b/test/src/unit-regression.cpp @@ -31,6 +31,8 @@ SOFTWARE. #include "json.hpp" using nlohmann::json; +#include + TEST_CASE("regression tests") { SECTION("issue #60 - Double quotation mark is not parsed correctly") @@ -440,4 +442,19 @@ TEST_CASE("regression tests") CHECK(at_integer == val_integer); } + + SECTION("issue #306 - Parsing fails without space at end of file") + { + for (auto filename : + { + "test/data/regression/broken_file.json", + "test/data/regression/working_file.json" + }) + { + CAPTURE(filename); + json j; + std::ifstream f(filename); + CHECK_NOTHROW(j << f); + } + } }