Skip to content

Commit

Permalink
fixed #306
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Sep 11, 2016
1 parent 8ea0ee5 commit 2daab5a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
2 changes: 1 addition & 1 deletion src/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8592,7 +8592,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();
Expand Down
2 changes: 1 addition & 1 deletion src/json.hpp.re2c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions test/data/regression/broken_file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"AmbientOcclusion":false,"AnisotropicFiltering":16,"FOV":90,"FullScreen":true,"MipmapLevel":4,"RenderDistance":4,"VSync":true,"WindowResX":1920,"WindowResY":1080}
1 change: 1 addition & 0 deletions test/data/regression/working_file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"AmbientOcclusion":false,"AnisotropicFiltering":16,"FOV":90,"FullScreen":true,"MipmapLevel":4,"RenderDistance":4,"VSync":true,"WindowResX":1920,"WindowResY":1080}
17 changes: 17 additions & 0 deletions test/src/unit-regression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ SOFTWARE.
#include "json.hpp"
using nlohmann::json;

#include <fstream>

TEST_CASE("regression tests")
{
SECTION("issue #60 - Double quotation mark is not parsed correctly")
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 2daab5a

Please sign in to comment.