From f909f2ab3e723e265d0d987b9e38eaa633e6d869 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Fri, 2 Dec 2022 13:30:54 +0100 Subject: [PATCH] [chip-tool] Allow the string 'null' to be used for TypedComplexArgument of Nullable type --- examples/chip-tool/commands/clusters/ComplexArgument.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/chip-tool/commands/clusters/ComplexArgument.h b/examples/chip-tool/commands/clusters/ComplexArgument.h index 8684116893cd12..795de9fb7138f6 100644 --- a/examples/chip-tool/commands/clusters/ComplexArgument.h +++ b/examples/chip-tool/commands/clusters/ComplexArgument.h @@ -29,7 +29,9 @@ #include "JsonParser.h" -constexpr uint8_t kMaxLabelLength = 100; +constexpr uint8_t kMaxLabelLength = 100; +constexpr const char kNullString[] = "null"; +constexpr const char kNullStringLen = ArraySize(kNullString) - 1 /* ignore \0 */; class ComplexArgumentParser { @@ -326,7 +328,11 @@ class TypedComplexArgument : public ComplexArgument CHIP_ERROR Parse(const char * label, const char * json) { Json::Value value; - if (!JsonParser::ParseComplexArgument(label, json, value)) + if (strncmp(kNullString, json, kNullStringLen) == 0 && strlen(json) == kNullStringLen) + { + value = Json::nullValue; + } + else if (!JsonParser::ParseComplexArgument(label, json, value)) { return CHIP_ERROR_INVALID_ARGUMENT; }