From 28f92f83b1104e877f59b024818962fe451a5c67 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Fri, 8 Jul 2022 18:10:45 +0200 Subject: [PATCH] [chip-tool] Make sure the multiple arguments separator for multiple write onto a single transation does not collide with the comma separator from the argument value itself (#20413) --- examples/chip-tool/commands/common/Command.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/chip-tool/commands/common/Command.cpp b/examples/chip-tool/commands/common/Command.cpp index 59812076cfde75..1c645754788d8e 100644 --- a/examples/chip-tool/commands/common/Command.cpp +++ b/examples/chip-tool/commands/common/Command.cpp @@ -55,7 +55,7 @@ bool Command::InitArguments(int argc, char ** argv) } } - VerifyOrExit((size_t)(argc) >= mandatoryArgsCount && (argvExtraArgsCount == 0 || (argvExtraArgsCount && optionalArgsCount)), + VerifyOrExit((size_t) (argc) >= mandatoryArgsCount && (argvExtraArgsCount == 0 || (argvExtraArgsCount && optionalArgsCount)), ChipLogError(chipTool, "InitArgs: Wrong arguments number: %d instead of %u", argc, static_cast(mandatoryArgsCount))); @@ -312,7 +312,11 @@ bool Command::InitArgument(size_t argIndex, char * argValue) while (ss.good()) { std::string valueAsString; - getline(ss, valueAsString, ','); + // By default the parameter separator is ";" in order to not collapse with the argument itself if it contains commas + // (e.g a struct argument with multiple fields). In case one needs to use ";" it can be overriden with the following + // environment variable. + constexpr const char * kSeparatorVariable = "CHIPTOOL_CUSTOM_ARGUMENTS_SEPARATOR"; + getline(ss, valueAsString, getenv(kSeparatorVariable) ? getenv(kSeparatorVariable)[0] : ';'); CustomArgument * customArgument = new CustomArgument(); vectorArgument->push_back(customArgument);