🐛 parsing erroneous files yields an exception (#366)
This commit is contained in:
parent
ed611119d9
commit
4bb41d065b
3 changed files with 18 additions and 0 deletions
|
@ -7597,6 +7597,12 @@ class basic_json
|
|||
explicit lexer(std::istream& s)
|
||||
: m_stream(&s), m_line_buffer()
|
||||
{
|
||||
// immediately abort if stream is erroneous
|
||||
if (s.fail())
|
||||
{
|
||||
throw std::invalid_argument("stream error: " + std::string(strerror(errno)));
|
||||
}
|
||||
|
||||
// fill buffer
|
||||
fill_line_buffer();
|
||||
|
||||
|
|
|
@ -7597,6 +7597,12 @@ class basic_json
|
|||
explicit lexer(std::istream& s)
|
||||
: m_stream(&s), m_line_buffer()
|
||||
{
|
||||
// immediately abort if stream is erroneous
|
||||
if (s.fail())
|
||||
{
|
||||
throw std::invalid_argument("stream error: " + std::string(strerror(errno)));
|
||||
}
|
||||
|
||||
// fill buffer
|
||||
fill_line_buffer();
|
||||
|
||||
|
|
|
@ -495,4 +495,10 @@ TEST_CASE("regression tests")
|
|||
json j = json::parse("22e2222");
|
||||
CHECK(j == json());
|
||||
}
|
||||
|
||||
SECTION("issue #366 - json::parse on failed stream gets stuck")
|
||||
{
|
||||
std::ifstream f("file_not_found.json");
|
||||
CHECK_THROWS_AS(json::parse(f), std::invalid_argument);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue