Validate against empty synonym string.

This commit is contained in:
Kishore Nallan 2021-06-11 20:56:48 +05:30
parent 0d5eef664e
commit 0716da0057
2 changed files with 13 additions and 2 deletions

View File

@ -229,8 +229,8 @@ struct synonym_t {
return Option<bool>(400, "Could not find an array of `synonyms`");
}
for(const auto & synonym: synonym_json["synonyms"]) {
if(!synonym.is_string()) {
for(const auto& synonym: synonym_json["synonyms"]) {
if(!synonym.is_string() || synonym == "") {
return Option<bool>(400, "Could not find a valid string array of `synonyms`");
}

View File

@ -130,6 +130,17 @@ TEST_F(CollectionSynonymsTest, SynonymParsingFromJson) {
ASSERT_FALSE(syn_op.ok());
ASSERT_STREQ("Could not find an array of `synonyms`", syn_op.error().c_str());
// empty string in synonym list
nlohmann::json syn_json_bad_type4 = {
{"id", "syn-1"},
{"root", "Ocean"},
{"synonyms", {""} }
};
syn_op = synonym_t::parse(syn_json_bad_type4, synonym);
ASSERT_FALSE(syn_op.ok());
ASSERT_STREQ("Could not find a valid string array of `synonyms`", syn_op.error().c_str());
// root bad type
nlohmann::json syn_json_root_bad_type = {