mirror of
https://github.com/typesense/typesense.git
synced 2025-05-21 14:12:27 +08:00
Validate against empty synonym string.
This commit is contained in:
parent
0d5eef664e
commit
0716da0057
@ -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`");
|
||||
}
|
||||
|
||||
|
@ -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 = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user