mirror of
https://github.com/nlohmann/json.git
synced 2025-07-29 23:01:16 +03:00
* Possible fix for #4485 Throw's an exception when i is nullptr, also added a testcase for this scenario though most likely in the wrong test file.cpp * quick cleanup * Fix compile issues * moved tests around, changed exceptions, removed a possibly unneeded include * add back include <memory> for testing something * Ninja doesn't like not having a \n, at end of file, adding it back * update input_adapter file to deal with empty/null file ptr. * ran make pretty * added test for inputadapter * ran make amalgamate * Update tests/src/unit-deserialization.cpp Co-authored-by: Niels Lohmann <niels.lohmann@gmail.com> * Update tests/src/unit-deserialization.cpp Co-authored-by: Niels Lohmann <niels.lohmann@gmail.com> * Update input adapters.hpp with new includes * fix unabigious use of _, (there was a double declare) * did the amalagamate * rm duplicate includes * make amalgamate again * reorder * amalgamate * moved it above * amalgamate --------- Co-authored-by: Jordan <jordan-hoang@users.noreply.github.com> Co-authored-by: Niels Lohmann <niels.lohmann@gmail.com>
This commit is contained in:
@ -23,6 +23,7 @@
|
|||||||
#include <istream> // istream
|
#include <istream> // istream
|
||||||
#endif // JSON_NO_IO
|
#endif // JSON_NO_IO
|
||||||
|
|
||||||
|
#include <nlohmann/detail/exceptions.hpp>
|
||||||
#include <nlohmann/detail/iterators/iterator_traits.hpp>
|
#include <nlohmann/detail/iterators/iterator_traits.hpp>
|
||||||
#include <nlohmann/detail/macro_scope.hpp>
|
#include <nlohmann/detail/macro_scope.hpp>
|
||||||
#include <nlohmann/detail/meta/type_traits.hpp>
|
#include <nlohmann/detail/meta/type_traits.hpp>
|
||||||
@ -420,6 +421,10 @@ typename container_input_adapter_factory_impl::container_input_adapter_factory<C
|
|||||||
// Special cases with fast paths
|
// Special cases with fast paths
|
||||||
inline file_input_adapter input_adapter(std::FILE* file)
|
inline file_input_adapter input_adapter(std::FILE* file)
|
||||||
{
|
{
|
||||||
|
if (file == nullptr)
|
||||||
|
{
|
||||||
|
JSON_THROW(parse_error::create(101, 0, "attempting to parse an empty input; check that your input string or stream contains the expected JSON", nullptr));
|
||||||
|
}
|
||||||
return file_input_adapter(file);
|
return file_input_adapter(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -446,6 +451,10 @@ template < typename CharT,
|
|||||||
int >::type = 0 >
|
int >::type = 0 >
|
||||||
contiguous_bytes_input_adapter input_adapter(CharT b)
|
contiguous_bytes_input_adapter input_adapter(CharT b)
|
||||||
{
|
{
|
||||||
|
if (b == nullptr)
|
||||||
|
{
|
||||||
|
JSON_THROW(parse_error::create(101, 0, "attempting to parse an empty input; check that your input string or stream contains the expected JSON", nullptr));
|
||||||
|
}
|
||||||
auto length = std::strlen(reinterpret_cast<const char*>(b));
|
auto length = std::strlen(reinterpret_cast<const char*>(b));
|
||||||
const auto* ptr = reinterpret_cast<const char*>(b);
|
const auto* ptr = reinterpret_cast<const char*>(b);
|
||||||
return input_adapter(ptr, ptr + length);
|
return input_adapter(ptr, ptr + length);
|
||||||
|
@ -6233,6 +6233,8 @@ NLOHMANN_JSON_NAMESPACE_END
|
|||||||
#include <istream> // istream
|
#include <istream> // istream
|
||||||
#endif // JSON_NO_IO
|
#endif // JSON_NO_IO
|
||||||
|
|
||||||
|
// #include <nlohmann/detail/exceptions.hpp>
|
||||||
|
|
||||||
// #include <nlohmann/detail/iterators/iterator_traits.hpp>
|
// #include <nlohmann/detail/iterators/iterator_traits.hpp>
|
||||||
|
|
||||||
// #include <nlohmann/detail/macro_scope.hpp>
|
// #include <nlohmann/detail/macro_scope.hpp>
|
||||||
@ -6633,6 +6635,10 @@ typename container_input_adapter_factory_impl::container_input_adapter_factory<C
|
|||||||
// Special cases with fast paths
|
// Special cases with fast paths
|
||||||
inline file_input_adapter input_adapter(std::FILE* file)
|
inline file_input_adapter input_adapter(std::FILE* file)
|
||||||
{
|
{
|
||||||
|
if (file == nullptr)
|
||||||
|
{
|
||||||
|
JSON_THROW(parse_error::create(101, 0, "attempting to parse an empty input; check that your input string or stream contains the expected JSON", nullptr));
|
||||||
|
}
|
||||||
return file_input_adapter(file);
|
return file_input_adapter(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6659,6 +6665,10 @@ template < typename CharT,
|
|||||||
int >::type = 0 >
|
int >::type = 0 >
|
||||||
contiguous_bytes_input_adapter input_adapter(CharT b)
|
contiguous_bytes_input_adapter input_adapter(CharT b)
|
||||||
{
|
{
|
||||||
|
if (b == nullptr)
|
||||||
|
{
|
||||||
|
JSON_THROW(parse_error::create(101, 0, "attempting to parse an empty input; check that your input string or stream contains the expected JSON", nullptr));
|
||||||
|
}
|
||||||
auto length = std::strlen(reinterpret_cast<const char*>(b));
|
auto length = std::strlen(reinterpret_cast<const char*>(b));
|
||||||
const auto* ptr = reinterpret_cast<const char*>(b);
|
const auto* ptr = reinterpret_cast<const char*>(b);
|
||||||
return input_adapter(ptr, ptr + length);
|
return input_adapter(ptr, ptr + length);
|
||||||
|
@ -20,7 +20,6 @@ TEST_CASE("concepts")
|
|||||||
// a, b: values of type X: json
|
// a, b: values of type X: json
|
||||||
|
|
||||||
// TABLE 96 - Container Requirements
|
// TABLE 96 - Container Requirements
|
||||||
|
|
||||||
// X::value_type must return T
|
// X::value_type must return T
|
||||||
CHECK((std::is_same<json::value_type, json>::value));
|
CHECK((std::is_same<json::value_type, json>::value));
|
||||||
|
|
||||||
|
@ -361,6 +361,10 @@ TEST_CASE("deserialization")
|
|||||||
"start_object()", "key(one)", "number_unsigned(1)",
|
"start_object()", "key(one)", "number_unsigned(1)",
|
||||||
"end_object()", "parse_error(29)"
|
"end_object()", "parse_error(29)"
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const char* string = nullptr;
|
||||||
|
CHECK_THROWS_WITH_AS(_ = json::parse(string), "[json.exception.parse_error.101] parse error: attempting to parse an empty input; check that your input string or stream contains the expected JSON", json::parse_error&);
|
||||||
|
CHECK_THROWS_WITH_AS(_ = json::parse(nullptr), "[json.exception.parse_error.101] parse error: attempting to parse an empty input; check that your input string or stream contains the expected JSON", json::parse_error&);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("operator<<")
|
SECTION("operator<<")
|
||||||
|
Reference in New Issue
Block a user