mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-30 18:57:32 +02:00
deserializeMsgPack() inserts null instead of returning NotSupported
This commit is contained in:
@ -6,6 +6,7 @@ HEAD
|
|||||||
|
|
||||||
* Removed support for `char` values, see below (issue #1498)
|
* Removed support for `char` values, see below (issue #1498)
|
||||||
* `deserializeJson()` leaves `\uXXXX` unchanged instead of returning `NotSupported`
|
* `deserializeJson()` leaves `\uXXXX` unchanged instead of returning `NotSupported`
|
||||||
|
* `deserializeMsgPack()` inserts `null` instead of returning `NotSupported`
|
||||||
|
|
||||||
> ### BREAKING CHANGES
|
> ### BREAKING CHANGES
|
||||||
>
|
>
|
||||||
|
@ -20,7 +20,8 @@ static void check(const char* input, U expected) {
|
|||||||
static void checkNotSupported(const char* input) {
|
static void checkNotSupported(const char* input) {
|
||||||
DynamicJsonDocument doc(4096);
|
DynamicJsonDocument doc(4096);
|
||||||
DeserializationError error = deserializeMsgPack(doc, input);
|
DeserializationError error = deserializeMsgPack(doc, input);
|
||||||
REQUIRE(error == DeserializationError::NotSupported);
|
REQUIRE(error == DeserializationError::Ok);
|
||||||
|
REQUIRE(doc.isNull());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -108,4 +108,51 @@ TEST_CASE("deserializeMsgPack() returns IncompleteInput") {
|
|||||||
SECTION("str 32") {
|
SECTION("str 32") {
|
||||||
checkAllSizes("\xdb\x00\x00\x00\x05hello", 10);
|
checkAllSizes("\xdb\x00\x00\x00\x05hello", 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("bin 8") {
|
||||||
|
checkAllSizes("\xc4\x01X", 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("bin 16") {
|
||||||
|
checkAllSizes("\xc5\x00\x01X", 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("bin 32") {
|
||||||
|
checkAllSizes("\xc6\x00\x00\x00\x01X", 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("ext 8") {
|
||||||
|
checkAllSizes("\xc7\x01\x01\x01", 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("ext 16") {
|
||||||
|
checkAllSizes("\xc8\x00\x01\x01\x01", 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("ext 32") {
|
||||||
|
checkAllSizes("\xc9\x00\x00\x00\x01\x01\x01", 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("fixext 1") {
|
||||||
|
checkAllSizes("\xd4\x01\x01", 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("fixext 2") {
|
||||||
|
checkAllSizes("\xd5\x01\x01\x02", 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("fixext 4") {
|
||||||
|
checkAllSizes("\xd6\x01\x01\x02\x03\x04", 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("fixext 8") {
|
||||||
|
checkAllSizes("\xd7\x01\x01\x02\x03\x04\x05\x06\x07\x08", 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("fixext 16") {
|
||||||
|
checkAllSizes(
|
||||||
|
"\xd8\x01\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E"
|
||||||
|
"\x0F\x10",
|
||||||
|
18);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,69 +5,78 @@
|
|||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <catch.hpp>
|
#include <catch.hpp>
|
||||||
|
|
||||||
static void checkNotSupported(const char* input) {
|
static void checkMsgPackDocument(const char* input, size_t inputSize,
|
||||||
|
const char* expectedJson) {
|
||||||
DynamicJsonDocument doc(4096);
|
DynamicJsonDocument doc(4096);
|
||||||
|
|
||||||
DeserializationError error = deserializeMsgPack(doc, input);
|
DeserializationError error = deserializeMsgPack(doc, input, inputSize);
|
||||||
|
|
||||||
REQUIRE(error == DeserializationError::NotSupported);
|
REQUIRE(error == DeserializationError::Ok);
|
||||||
|
std::string actualJson;
|
||||||
|
serializeJson(doc, actualJson);
|
||||||
|
REQUIRE(actualJson == expectedJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void checkMsgPackError(const char* input, size_t inputSize,
|
||||||
|
DeserializationError expectedError) {
|
||||||
|
DynamicJsonDocument doc(4096);
|
||||||
|
|
||||||
|
DeserializationError error = deserializeMsgPack(doc, input, inputSize);
|
||||||
|
|
||||||
|
REQUIRE(error == expectedError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("deserializeMsgPack() return NotSupported") {
|
TEST_CASE("deserializeMsgPack() return NotSupported") {
|
||||||
SECTION("bin 8") {
|
SECTION("bin 8") {
|
||||||
checkNotSupported("\xc4");
|
checkMsgPackDocument("\x92\xc4\x01X\x2A", 5, "[null,42]");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("bin 16") {
|
SECTION("bin 16") {
|
||||||
checkNotSupported("\xc5");
|
checkMsgPackDocument("\x92\xc5\x00\x01X\x2A", 6, "[null,42]");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("bin 32") {
|
SECTION("bin 32") {
|
||||||
checkNotSupported("\xc6");
|
checkMsgPackDocument("\x92\xc6\x00\x00\x00\x01X\x2A", 8, "[null,42]");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("ext 8") {
|
SECTION("ext 8") {
|
||||||
checkNotSupported("\xc7");
|
checkMsgPackDocument("\x92\xc7\x01\x01\x01\x2A", 6, "[null,42]");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("ext 16") {
|
SECTION("ext 16") {
|
||||||
checkNotSupported("\xc8");
|
checkMsgPackDocument("\x92\xc8\x00\x01\x01\x01\x2A", 7, "[null,42]");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("ext 32") {
|
SECTION("ext 32") {
|
||||||
checkNotSupported("\xc9");
|
checkMsgPackDocument("\x92\xc9\x00\x00\x00\x01\x01\x01\x2A", 9,
|
||||||
|
"[null,42]");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("fixext 1") {
|
SECTION("fixext 1") {
|
||||||
checkNotSupported("\xd4");
|
checkMsgPackDocument("\x92\xd4\x01\x01\x2A", 5, "[null,42]");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("fixext 2") {
|
SECTION("fixext 2") {
|
||||||
checkNotSupported("\xd5");
|
checkMsgPackDocument("\x92\xd5\x01\x01\x02\x2A", 6, "[null,42]");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("fixext 4") {
|
SECTION("fixext 4") {
|
||||||
checkNotSupported("\xd6");
|
checkMsgPackDocument("\x92\xd6\x01\x01\x02\x03\x04\x2A", 8, "[null,42]");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("fixext 8") {
|
SECTION("fixext 8") {
|
||||||
checkNotSupported("\xd7");
|
checkMsgPackDocument("\x92\xd7\x01\x01\x02\x03\x04\x05\x06\x07\x08\x2A", 12,
|
||||||
|
"[null,42]");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("fixext 16") {
|
SECTION("fixext 16") {
|
||||||
checkNotSupported("\xd8");
|
checkMsgPackDocument(
|
||||||
}
|
"\x92\xd8\x01\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E"
|
||||||
|
"\x0F\x10\x2A",
|
||||||
SECTION("unsupported in array") {
|
20, "[null,42]");
|
||||||
checkNotSupported("\x91\xc4");
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("unsupported in map") {
|
|
||||||
checkNotSupported("\x81\xc4\x00\xA1H");
|
|
||||||
checkNotSupported("\x81\xA1H\xc4\x00");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("integer as key") {
|
SECTION("integer as key") {
|
||||||
checkNotSupported("\x81\x01\xA1H");
|
checkMsgPackError("\x81\x01\xA1H", 3, DeserializationError::InvalidInput);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,11 +40,6 @@ class MsgPackDeserializer {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool notSupported() {
|
|
||||||
_error = DeserializationError::NotSupported;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename TFilter>
|
template <typename TFilter>
|
||||||
bool parseVariant(VariantData &variant, TFilter filter,
|
bool parseVariant(VariantData &variant, TFilter filter,
|
||||||
NestingLimit nestingLimit) {
|
NestingLimit nestingLimit) {
|
||||||
@ -74,41 +69,23 @@ class MsgPackDeserializer {
|
|||||||
variant.setBoolean(true);
|
variant.setBoolean(true);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case 0xc4: // bin 8
|
case 0xc4: // bin 8 (not supported)
|
||||||
if (allowValue)
|
return skipString<uint8_t>();
|
||||||
return notSupported();
|
|
||||||
else
|
|
||||||
return skipString<uint8_t>();
|
|
||||||
|
|
||||||
case 0xc5: // bin 16
|
case 0xc5: // bin 16 (not supported)
|
||||||
if (allowValue)
|
return skipString<uint16_t>();
|
||||||
return notSupported();
|
|
||||||
else
|
|
||||||
return skipString<uint16_t>();
|
|
||||||
|
|
||||||
case 0xc6: // bin 32
|
case 0xc6: // bin 32 (not supported)
|
||||||
if (allowValue)
|
return skipString<uint32_t>();
|
||||||
return notSupported();
|
|
||||||
else
|
|
||||||
return skipString<uint32_t>();
|
|
||||||
|
|
||||||
case 0xc7: // ext 8
|
case 0xc7: // ext 8 (not supported)
|
||||||
if (allowValue)
|
return skipExt<uint8_t>();
|
||||||
return notSupported();
|
|
||||||
else
|
|
||||||
return skipExt<uint8_t>();
|
|
||||||
|
|
||||||
case 0xc8: // ext 16
|
case 0xc8: // ext 16 (not supported)
|
||||||
if (allowValue)
|
return skipExt<uint16_t>();
|
||||||
return notSupported();
|
|
||||||
else
|
|
||||||
return skipExt<uint16_t>();
|
|
||||||
|
|
||||||
case 0xc9: // ext 32
|
case 0xc9: // ext 32 (not supported)
|
||||||
if (allowValue)
|
return skipExt<uint32_t>();
|
||||||
return notSupported();
|
|
||||||
else
|
|
||||||
return skipExt<uint32_t>();
|
|
||||||
|
|
||||||
case 0xca:
|
case 0xca:
|
||||||
if (allowValue)
|
if (allowValue)
|
||||||
@ -141,14 +118,14 @@ class MsgPackDeserializer {
|
|||||||
return skipBytes(4);
|
return skipBytes(4);
|
||||||
|
|
||||||
case 0xcf:
|
case 0xcf:
|
||||||
if (allowValue)
|
|
||||||
#if ARDUINOJSON_USE_LONG_LONG
|
#if ARDUINOJSON_USE_LONG_LONG
|
||||||
|
if (allowValue)
|
||||||
return readInteger<uint64_t>(variant);
|
return readInteger<uint64_t>(variant);
|
||||||
#else
|
|
||||||
return notSupported();
|
|
||||||
#endif
|
|
||||||
else
|
else
|
||||||
return skipBytes(8);
|
return skipBytes(8);
|
||||||
|
#else
|
||||||
|
return skipBytes(8); // not supported
|
||||||
|
#endif
|
||||||
|
|
||||||
case 0xd0:
|
case 0xd0:
|
||||||
if (allowValue)
|
if (allowValue)
|
||||||
@ -169,44 +146,29 @@ class MsgPackDeserializer {
|
|||||||
return skipBytes(4);
|
return skipBytes(4);
|
||||||
|
|
||||||
case 0xd3:
|
case 0xd3:
|
||||||
if (allowValue)
|
|
||||||
#if ARDUINOJSON_USE_LONG_LONG
|
#if ARDUINOJSON_USE_LONG_LONG
|
||||||
|
if (allowValue)
|
||||||
return readInteger<int64_t>(variant);
|
return readInteger<int64_t>(variant);
|
||||||
|
else
|
||||||
|
return skipBytes(8); // not supported
|
||||||
#else
|
#else
|
||||||
return notSupported();
|
return skipBytes(8);
|
||||||
#endif
|
#endif
|
||||||
else
|
|
||||||
return skipBytes(8);
|
|
||||||
|
|
||||||
case 0xd4: // fixext 1
|
case 0xd4: // fixext 1 (not supported)
|
||||||
if (allowValue)
|
return skipBytes(2);
|
||||||
return notSupported();
|
|
||||||
else
|
|
||||||
return skipBytes(2);
|
|
||||||
|
|
||||||
case 0xd5: // fixext 2
|
case 0xd5: // fixext 2 (not supported)
|
||||||
if (allowValue)
|
return skipBytes(3);
|
||||||
return notSupported();
|
|
||||||
else
|
|
||||||
return skipBytes(3);
|
|
||||||
|
|
||||||
case 0xd6: // fixext 4
|
case 0xd6: // fixext 4 (not supported)
|
||||||
if (allowValue)
|
return skipBytes(5);
|
||||||
return notSupported();
|
|
||||||
else
|
|
||||||
return skipBytes(5);
|
|
||||||
|
|
||||||
case 0xd7: // fixext 8
|
case 0xd7: // fixext 8 (not supported)
|
||||||
if (allowValue)
|
return skipBytes(9);
|
||||||
return notSupported();
|
|
||||||
else
|
|
||||||
return skipBytes(9);
|
|
||||||
|
|
||||||
case 0xd8: // fixext 16
|
case 0xd8: // fixext 16 (not supported)
|
||||||
if (allowValue)
|
return skipBytes(17);
|
||||||
return notSupported();
|
|
||||||
else
|
|
||||||
return skipBytes(17);
|
|
||||||
|
|
||||||
case 0xd9:
|
case 0xd9:
|
||||||
if (allowValue)
|
if (allowValue)
|
||||||
@ -508,7 +470,7 @@ class MsgPackDeserializer {
|
|||||||
return readString<uint32_t>();
|
return readString<uint32_t>();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return notSupported();
|
return invalidInput();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user