Unverified Commit 32bda1a7 by Niels Lohmann

Merge branches 'develop' and 'mkdocs' of https://github.com/nlohmann/json into mkdocs

parents e3d9b3d7 92125907
...@@ -11,11 +11,8 @@ jobs: ...@@ -11,11 +11,8 @@ jobs:
name: Install required tools name: Install required tools
command: 'apt-get update && apt-get install -y gcc g++ git cmake' command: 'apt-get update && apt-get install -y gcc g++ git cmake'
- run: - run:
name: Show versions
command: 'g++ --version ; uname -a; cmake --version'
- run:
name: Run CMake name: Run CMake
command: 'mkdir build ; cd build ; cmake ..' command: 'mkdir build ; cd build ; cmake .. -DJSON_BuildTests=On'
- run: - run:
name: Compile name: Compile
command: 'cmake --build build' command: 'cmake --build build'
...@@ -34,11 +31,8 @@ jobs: ...@@ -34,11 +31,8 @@ jobs:
name: Install required tools name: Install required tools
command: 'pacman -Sy --noconfirm base base-devel gcc git cmake' command: 'pacman -Sy --noconfirm base base-devel gcc git cmake'
- run: - run:
name: Show versions
command: 'g++ --version ; uname -a; cmake --version'
- run:
name: Run CMake name: Run CMake
command: 'mkdir build ; cd build ; cmake ..' command: 'mkdir build ; cd build ; cmake .. -DJSON_BuildTests=On'
- run: - run:
name: Compile name: Compile
command: 'cmake --build build' command: 'cmake --build build'
......
...@@ -14,4 +14,3 @@ assignees: '' ...@@ -14,4 +14,3 @@ assignees: ''
#### How would the feature be usable for other users? #### How would the feature be usable for other users?
<!-- Include sample usage where appropriate. --> <!-- Include sample usage where appropriate. -->
...@@ -7,6 +7,8 @@ assignees: '' ...@@ -7,6 +7,8 @@ assignees: ''
--- ---
<!-- Provide a concise summary of the issue in the title above. -->
#### What do you want to achieve? #### What do you want to achieve?
<!-- Please describe the feature as detailed as possible. --> <!-- Please describe the feature as detailed as possible. -->
...@@ -17,6 +19,10 @@ assignees: '' ...@@ -17,6 +19,10 @@ assignees: ''
<!-- There is a full documentation of the API: https://nlohmann.github.io/json/ --> <!-- There is a full documentation of the API: https://nlohmann.github.io/json/ -->
<!-- There is a detailed README file: https://github.com/nlohmann/json/blob/develop/README.md --> <!-- There is a detailed README file: https://github.com/nlohmann/json/blob/develop/README.md -->
#### Can you provide a small code example?
<!-- Please understand that we cannot analyze and debug large code bases. -->
#### Which compiler and operating system are you using? #### Which compiler and operating system are you using?
<!-- Include as many relevant details about the environment you experienced the bug in. --> <!-- Include as many relevant details about the environment you experienced the bug in. -->
......
...@@ -10,7 +10,7 @@ jobs: ...@@ -10,7 +10,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- name: cmake - name: cmake
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On
- name: build - name: build
run: cmake --build build --parallel 10 run: cmake --build build --parallel 10
- name: test - name: test
......
...@@ -10,7 +10,7 @@ jobs: ...@@ -10,7 +10,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- name: cmake - name: cmake
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug run: cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On
- name: build - name: build
run: cmake --build build --parallel 10 run: cmake --build build --parallel 10
- name: test - name: test
......
...@@ -10,7 +10,7 @@ jobs: ...@@ -10,7 +10,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- name: cmake - name: cmake
run: cmake -S . -B build -G "Visual Studio 16 2019" -D CMAKE_BUILD_TYPE=Debug run: cmake -S . -B build -G "Visual Studio 16 2019" -D CMAKE_BUILD_TYPE=Debug -DJSON_BuildTests=On
- name: build - name: build
run: cmake --build build --parallel 10 run: cmake --build build --parallel 10
- name: test - name: test
......
...@@ -321,13 +321,9 @@ script: ...@@ -321,13 +321,9 @@ script:
# by default, use the single-header version # by default, use the single-header version
- if [[ "${MULTIPLE_HEADERS}" == "" ]]; then export MULTIPLE_HEADERS=OFF; fi - if [[ "${MULTIPLE_HEADERS}" == "" ]]; then export MULTIPLE_HEADERS=OFF; fi
# show OS/compiler version
- uname -a
- $CXX --version
# compile and execute unit tests # compile and execute unit tests
- mkdir -p build && cd build - mkdir -p build && cd build
- cmake .. ${CMAKE_OPTIONS} -DJSON_MultipleHeaders=${MULTIPLE_HEADERS} -GNinja && cmake --build . --config Release - cmake .. ${CMAKE_OPTIONS} -DJSON_MultipleHeaders=${MULTIPLE_HEADERS} -DJSON_BuildTests=On -GNinja && cmake --build . --config Release
- ctest -C Release --timeout 2700 -V -j - ctest -C Release --timeout 2700 -V -j
- cd .. - cd ..
......
...@@ -112,7 +112,7 @@ before_build: ...@@ -112,7 +112,7 @@ before_build:
# for with_win_header build, inject the inclusion of Windows.h to the single-header library # for with_win_header build, inject the inclusion of Windows.h to the single-header library
- ps: if ($env:name -Eq "with_win_header") { $header_path = "single_include\nlohmann\json.hpp" } - ps: if ($env:name -Eq "with_win_header") { $header_path = "single_include\nlohmann\json.hpp" }
- ps: if ($env:name -Eq "with_win_header") { "#include <Windows.h>`n" + (Get-Content $header_path | Out-String) | Set-Content $header_path } - ps: if ($env:name -Eq "with_win_header") { "#include <Windows.h>`n" + (Get-Content $header_path | Out-String) | Set-Content $header_path }
- if "%GENERATOR%"=="Ninja" (cmake . -G "%GENERATOR%" -DCMAKE_BUILD_TYPE="%configuration%" -DCMAKE_CXX_FLAGS="%CXX_FLAGS%" -DCMAKE_EXE_LINKER_FLAGS="%LINKER_FLAGS%" -DCMAKE_IGNORE_PATH="C:/Program Files/Git/usr/bin") else (cmake . -G "%GENERATOR%" -A "%GENERATOR_PLATFORM%" -DCMAKE_CXX_FLAGS="%CXX_FLAGS%" -DCMAKE_EXE_LINKER_FLAGS="%LINKER_FLAGS%" -DCMAKE_IGNORE_PATH="C:/Program Files/Git/usr/bin") - if "%GENERATOR%"=="Ninja" (cmake . -G "%GENERATOR%" -DCMAKE_BUILD_TYPE="%configuration%" -DCMAKE_CXX_FLAGS="%CXX_FLAGS%" -DCMAKE_EXE_LINKER_FLAGS="%LINKER_FLAGS%" -DCMAKE_IGNORE_PATH="C:/Program Files/Git/usr/bin" -DJSON_BuildTests=On) else (cmake . -G "%GENERATOR%" -A "%GENERATOR_PLATFORM%" -DCMAKE_CXX_FLAGS="%CXX_FLAGS%" -DCMAKE_EXE_LINKER_FLAGS="%LINKER_FLAGS%" -DCMAKE_IGNORE_PATH="C:/Program Files/Git/usr/bin" -DJSON_BuildTests=On)
build_script: build_script:
- cmake --build . --config "%configuration%" - cmake --build . --config "%configuration%"
......
...@@ -331,13 +331,14 @@ inline input_stream_adapter input_adapter(std::istream&& stream) ...@@ -331,13 +331,14 @@ inline input_stream_adapter input_adapter(std::istream&& stream)
return input_stream_adapter(stream); return input_stream_adapter(stream);
} }
template<typename CharT, template<typename CharT, typename SizeT,
typename std::enable_if< typename std::enable_if<
std::is_pointer<CharT>::value and std::is_pointer<CharT>::value and
std::is_integral<typename std::remove_pointer<CharT>::type>::value and std::is_integral<typename std::remove_pointer<CharT>::type>::value and
not std::is_same<SizeT, bool>::value and
sizeof(typename std::remove_pointer<CharT>::type) == 1, sizeof(typename std::remove_pointer<CharT>::type) == 1,
int>::type = 0> 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<const char*>(b), l); return input_buffer_adapter(reinterpret_cast<const char*>(b), l);
} }
......
...@@ -452,7 +452,7 @@ class json_sax_dom_callback_parser ...@@ -452,7 +452,7 @@ class json_sax_dom_callback_parser
ref_stack.pop_back(); ref_stack.pop_back();
keep_stack.pop_back(); keep_stack.pop_back();
if (not ref_stack.empty() and ref_stack.back() and ref_stack.back()->is_object()) if (not ref_stack.empty() and ref_stack.back() and ref_stack.back()->is_structured())
{ {
// remove discarded value // remove discarded value
for (auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it) for (auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
......
...@@ -1367,7 +1367,7 @@ scan_number_done: ...@@ -1367,7 +1367,7 @@ scan_number_done:
std::string result; std::string result;
for (const auto c : token_string) for (const auto c : token_string)
{ {
if ('\x00' <= c and c <= '\x1F') if (static_cast<unsigned char>(c) <= '\x1F')
{ {
// escape control characters // escape control characters
std::array<char, 9> cs{{}}; std::array<char, 9> cs{{}};
......
...@@ -3207,7 +3207,7 @@ class basic_json ...@@ -3207,7 +3207,7 @@ class basic_json
not std::is_same<ValueType, typename string_t::value_type>::value and not std::is_same<ValueType, typename string_t::value_type>::value and
not detail::is_basic_json<ValueType>::value not detail::is_basic_json<ValueType>::value
and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) and _MSC_VER <= 1914)) #if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) and _MSC_VER >= 1910 and _MSC_VER <= 1914))
and not std::is_same<ValueType, typename std::string_view>::value and not std::is_same<ValueType, typename std::string_view>::value
#endif #endif
and detail::is_detected<detail::get_template_function, const basic_json_t&, ValueType>::value and detail::is_detected<detail::get_template_function, const basic_json_t&, ValueType>::value
......
...@@ -4753,13 +4753,14 @@ inline input_stream_adapter input_adapter(std::istream&& stream) ...@@ -4753,13 +4753,14 @@ inline input_stream_adapter input_adapter(std::istream&& stream)
return input_stream_adapter(stream); return input_stream_adapter(stream);
} }
template<typename CharT, template<typename CharT, typename SizeT,
typename std::enable_if< typename std::enable_if<
std::is_pointer<CharT>::value and std::is_pointer<CharT>::value and
std::is_integral<typename std::remove_pointer<CharT>::type>::value and std::is_integral<typename std::remove_pointer<CharT>::type>::value and
not std::is_same<SizeT, bool>::value and
sizeof(typename std::remove_pointer<CharT>::type) == 1, sizeof(typename std::remove_pointer<CharT>::type) == 1,
int>::type = 0> 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<const char*>(b), l); return input_buffer_adapter(reinterpret_cast<const char*>(b), l);
} }
...@@ -5357,7 +5358,7 @@ class json_sax_dom_callback_parser ...@@ -5357,7 +5358,7 @@ class json_sax_dom_callback_parser
ref_stack.pop_back(); ref_stack.pop_back();
keep_stack.pop_back(); keep_stack.pop_back();
if (not ref_stack.empty() and ref_stack.back() and ref_stack.back()->is_object()) if (not ref_stack.empty() and ref_stack.back() and ref_stack.back()->is_structured())
{ {
// remove discarded value // remove discarded value
for (auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it) for (auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
...@@ -9456,7 +9457,7 @@ scan_number_done: ...@@ -9456,7 +9457,7 @@ scan_number_done:
std::string result; std::string result;
for (const auto c : token_string) for (const auto c : token_string)
{ {
if ('\x00' <= c and c <= '\x1F') if (static_cast<unsigned char>(c) <= '\x1F')
{ {
// escape control characters // escape control characters
std::array<char, 9> cs{{}}; std::array<char, 9> cs{{}};
...@@ -18999,7 +19000,7 @@ class basic_json ...@@ -18999,7 +19000,7 @@ class basic_json
not std::is_same<ValueType, typename string_t::value_type>::value and not std::is_same<ValueType, typename string_t::value_type>::value and
not detail::is_basic_json<ValueType>::value not detail::is_basic_json<ValueType>::value
and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) and _MSC_VER <= 1914)) #if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) and _MSC_VER >= 1910 and _MSC_VER <= 1914))
and not std::is_same<ValueType, typename std::string_view>::value and not std::is_same<ValueType, typename std::string_view>::value
#endif #endif
and detail::is_detected<detail::get_template_function, const basic_json_t&, ValueType>::value and detail::is_detected<detail::get_template_function, const basic_json_t&, ValueType>::value
......
...@@ -183,6 +183,7 @@ add_dependencies(json_unit download_test_data) ...@@ -183,6 +183,7 @@ add_dependencies(json_unit download_test_data)
############################################################################# #############################################################################
# Test the generated build configs # Test the generated build configs
############################################################################# #############################################################################
add_subdirectory(cmake_import) add_subdirectory(cmake_import)
add_subdirectory(cmake_import_minver) add_subdirectory(cmake_import_minver)
add_subdirectory(cmake_add_subdirectory) add_subdirectory(cmake_add_subdirectory)
......
...@@ -1489,6 +1489,18 @@ TEST_CASE("parser class") ...@@ -1489,6 +1489,18 @@ TEST_CASE("parser class")
[1,2,[3,4,5],4,5] [1,2,[3,4,5],4,5]
)"; )";
auto structured_array = R"(
[
1,
{
"foo": "bar"
},
{
"qux": "baz"
}
]
)";
SECTION("filter nothing") SECTION("filter nothing")
{ {
json j_object = json::parse(s_object, [](int, json::parse_event_t, const json&) json j_object = json::parse(s_object, [](int, json::parse_event_t, const json&)
...@@ -1557,6 +1569,41 @@ TEST_CASE("parser class") ...@@ -1557,6 +1569,41 @@ TEST_CASE("parser class")
CHECK (j_array == json({1, {3, 4, 5}, 4, 5})); CHECK (j_array == json({1, {3, 4, 5}, 4, 5}));
} }
SECTION("filter object in array")
{
json j_filtered1 = json::parse(structured_array, [](int, json::parse_event_t e, const json & parsed)
{
if (e == json::parse_event_t::object_end and parsed.contains("foo"))
{
return false;
}
else
{
return true;
}
});
// the specified object will be discarded, and removed.
CHECK (j_filtered1.size() == 2);
CHECK (j_filtered1 == json({1, {{"qux", "baz"}}}));
json j_filtered2 = json::parse(structured_array, [](int, json::parse_event_t e, const json & parsed)
{
if (e == json::parse_event_t::object_end)
{
return false;
}
else
{
return true;
}
});
// removed all objects in array.
CHECK (j_filtered2.size() == 1);
CHECK (j_filtered2 == json({1}));
}
SECTION("filter specific events") SECTION("filter specific events")
{ {
SECTION("first closing event") SECTION("first closing event")
......
...@@ -1890,6 +1890,28 @@ TEST_CASE("regression tests") ...@@ -1890,6 +1890,28 @@ TEST_CASE("regression tests")
json j = val; 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<T1, T2> is json constructible only if T1 and T2 are json constructible") SECTION("issue #1805 - A pair<T1, T2> is json constructible only if T1 and T2 are json constructible")
{ {
static_assert(!std::is_constructible<json, std::pair<std::string, NotSerializableData>>::value, ""); static_assert(!std::is_constructible<json, std::pair<std::string, NotSerializableData>>::value, "");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment