Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Validate against empty synonym string.

Kishore Nallan8dde664736a9
diff --git a/include/collection.h b/include/collection.h
index 2033c9b3..76f278b5 100644
--- a/include/collection.h
+++ b/include/collection.h
@@ -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`");
}
diff --git a/test/collection_synonyms_test.cpp b/test/collection_synonyms_test.cpp
index 15f040c1..efe69fdd 100644
--- a/test/collection_synonyms_test.cpp
+++ b/test/collection_synonyms_test.cpp
@@ -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 = {