mirror of
https://github.com/opencv/opencv.git
synced 2026-12-02 13:16:32 -06:00
Merge pull request #31312 from saanvimundra/fix/commandlineparser-key-validation-5x
core: report malformed CommandLineParser key descriptions
This commit is contained in:
@@ -230,6 +230,9 @@ CommandLineParser::CommandLineParser(int argc, const char* const argv[], const S
|
||||
for (size_t i = 0; i < k.size(); i++)
|
||||
{
|
||||
std::vector<String> l = impl->split_string(k[i], '|', true);
|
||||
if (l.size() < 3)
|
||||
CV_Error_(Error::StsParseError,
|
||||
("invalid key description '{%s}': expected 'names | default | help'", k[i].c_str()));
|
||||
CommandLineParserParams p;
|
||||
p.keys = impl->split_string(l[0]);
|
||||
p.def_value = l[1];
|
||||
|
||||
@@ -36,6 +36,14 @@ TEST(CommandLineParser, testFailure)
|
||||
EXPECT_FALSE(parser.check());
|
||||
}
|
||||
|
||||
TEST(CommandLineParser, testMalformedKeyDescription)
|
||||
{
|
||||
const char* argv[] = {"<bin>"};
|
||||
const int argc = 1;
|
||||
EXPECT_THROW(cv::CommandLineParser(argc, argv, "{ a }"), cv::Exception);
|
||||
EXPECT_THROW(cv::CommandLineParser(argc, argv, "{ a | 1 }"), cv::Exception);
|
||||
}
|
||||
|
||||
TEST(CommandLineParser, testHas_noValues)
|
||||
{
|
||||
const char* argv[] = {"<bin>", "-h", "--info"};
|
||||
|
||||
Reference in New Issue
Block a user