forked from bblanchon/ArduinoJson
JsonObject::createNestedArray()
returns JsonArray::invalid()
if key is null
This commit is contained in:
@ -5,6 +5,7 @@ HEAD
|
|||||||
----
|
----
|
||||||
|
|
||||||
* `JsonObject::createNestedObject()` returns `JsonObject::invalid()` if key is null (issue #1891)
|
* `JsonObject::createNestedObject()` returns `JsonObject::invalid()` if key is null (issue #1891)
|
||||||
|
* `JsonObject::createNestedArray()` returns `JsonArray::invalid()` if key is null
|
||||||
|
|
||||||
v5.13.5
|
v5.13.5
|
||||||
-------
|
-------
|
||||||
@ -492,4 +493,3 @@ v4.0
|
|||||||
> ### BREAKING CHANGES :warning:
|
> ### BREAKING CHANGES :warning:
|
||||||
>
|
>
|
||||||
> API changed significantly since v3, see [Migrating code to the new API](https://arduinojson.org/doc/migration/).
|
> API changed significantly since v3, see [Migrating code to the new API](https://arduinojson.org/doc/migration/).
|
||||||
|
|
||||||
|
@ -14,8 +14,10 @@ template <typename TStringRef>
|
|||||||
inline JsonArray &JsonObject::createNestedArray_impl(TStringRef key) {
|
inline JsonArray &JsonObject::createNestedArray_impl(TStringRef key) {
|
||||||
if (!_buffer) return JsonArray::invalid();
|
if (!_buffer) return JsonArray::invalid();
|
||||||
JsonArray &array = _buffer->createArray();
|
JsonArray &array = _buffer->createArray();
|
||||||
set(key, array);
|
if (set(key, array))
|
||||||
return array;
|
return array;
|
||||||
|
else
|
||||||
|
return JsonArray::invalid();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TStringRef>
|
template <typename TStringRef>
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
add_executable(JsonObjectTests
|
add_executable(JsonObjectTests
|
||||||
basics.cpp
|
basics.cpp
|
||||||
containsKey.cpp
|
containsKey.cpp
|
||||||
|
createNestedArray.cpp
|
||||||
createNestedObject.cpp
|
createNestedObject.cpp
|
||||||
get.cpp
|
get.cpp
|
||||||
invalid.cpp
|
invalid.cpp
|
||||||
|
23
test/JsonObject/createNestedArray.cpp
Normal file
23
test/JsonObject/createNestedArray.cpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// ArduinoJson - arduinojson.org
|
||||||
|
// Copyright Benoit Blanchon 2014-2023
|
||||||
|
// MIT License
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
#include <catch.hpp>
|
||||||
|
|
||||||
|
TEST_CASE("JsonObject::createNestedArray()") {
|
||||||
|
DynamicJsonBuffer _jsonBuffer;
|
||||||
|
JsonObject& _object = _jsonBuffer.createObject();
|
||||||
|
|
||||||
|
SECTION("success() should return true if key is non-null") {
|
||||||
|
JsonArray& arr = _object.createNestedArray("key");
|
||||||
|
REQUIRE(arr.success() == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("success() should return false if key is null") {
|
||||||
|
const char* null = 0;
|
||||||
|
JsonArray& arr = _object.createNestedArray(null);
|
||||||
|
REQUIRE(arr.success() == false);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user