From 225fa58f162d0d08281a6844920ca08bf7573682 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 20 May 2020 22:20:40 +0200 Subject: [PATCH 1/2] :construction: add fix from #1715 --- .../nlohmann/detail/input/input_adapters.hpp | 5 +++-- single_include/nlohmann/json.hpp | 5 +++-- test/src/unit-regression.cpp | 22 +++++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/detail/input/input_adapters.hpp b/include/nlohmann/detail/input/input_adapters.hpp index 7ad26d00..1a27cc9d 100644 --- a/include/nlohmann/detail/input/input_adapters.hpp +++ b/include/nlohmann/detail/input/input_adapters.hpp @@ -331,13 +331,14 @@ inline input_stream_adapter input_adapter(std::istream&& stream) return input_stream_adapter(stream); } -template::value and std::is_integral::type>::value and + not std::is_same::value and sizeof(typename std::remove_pointer::type) == 1, int>::type = 0> -input_buffer_adapter input_adapter(CharT b, std::size_t l) +input_buffer_adapter input_adapter(CharT b, SizeT l) { return input_buffer_adapter(reinterpret_cast(b), l); } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 5741303f..0530c678 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -4754,13 +4754,14 @@ inline input_stream_adapter input_adapter(std::istream&& stream) return input_stream_adapter(stream); } -template::value and std::is_integral::type>::value and + not std::is_same::value and sizeof(typename std::remove_pointer::type) == 1, int>::type = 0> -input_buffer_adapter input_adapter(CharT b, std::size_t l) +input_buffer_adapter input_adapter(CharT b, SizeT l) { return input_buffer_adapter(reinterpret_cast(b), l); } diff --git a/test/src/unit-regression.cpp b/test/src/unit-regression.cpp index 373344d8..8803ac90 100644 --- a/test/src/unit-regression.cpp +++ b/test/src/unit-regression.cpp @@ -1890,6 +1890,28 @@ TEST_CASE("regression tests") json j = val; } + SECTION("issue #1715 - json::from_cbor does not respect allow_exceptions = false when input is string literal") + { + SECTION("string literal") + { + json cbor = json::from_cbor("B", true, false); + CHECK(cbor.is_discarded()); + } + + SECTION("string array") + { + const char input[] = { 'B', 0x00 }; + json cbor = json::from_cbor(input, true, false); + CHECK(cbor.is_discarded()); + } + + SECTION("std::string") + { + json cbor = json::from_cbor(std::string("B"), true, false); + CHECK(cbor.is_discarded()); + } + } + SECTION("issue #1805 - A pair is json constructible only if T1 and T2 are json constructible") { static_assert(!std::is_constructible>::value, ""); From e44418ea2641d2f16989f1272f4e1c7e05af7d9d Mon Sep 17 00:00:00 2001 From: Quentin Barbarat Date: Wed, 27 May 2020 13:51:13 +0200 Subject: [PATCH 2/2] readme: fix typo in CMake FetchContent example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 077a60bc..39dff847 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,7 @@ Example: include(FetchContent) FetchContent_Declare(json - GIT_REPOSITORY https://github.com/nlohmann/json + GIT_REPOSITORY https://github.com/nlohmann/json.git GIT_TAG v3.7.3) FetchContent_GetProperties(json)