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

Fix id field filter value parsing crash. (#1817)

Harpreet Sangar6189fec0420f
diff --git a/src/filter.cpp b/src/filter.cpp
index 7d55ef91..95b512ba 100644
--- a/src/filter.cpp
+++ b/src/filter.cpp
@@ -459,6 +459,10 @@ Option<bool> toFilter(const std::string expression,
} else {
std::vector<std::string> doc_ids;
StringUtils::split_to_values(raw_value, doc_ids); // to handle backticks
+ if (doc_ids.empty()) {
+ return Option<bool>(400, empty_filter_err);
+ }
+
std::string seq_id_str;
StoreStatus seq_id_status = store->get(doc_id_prefix + doc_ids[0], seq_id_str);
if (seq_id_status == StoreStatus::FOUND) {
diff --git a/test/collection_filtering_test.cpp b/test/collection_filtering_test.cpp
index 128f64c2..54ad410d 100644
--- a/test/collection_filtering_test.cpp
+++ b/test/collection_filtering_test.cpp
@@ -1399,6 +1399,10 @@ TEST_F(CollectionFilteringTest, FilteringViaDocumentIds) {
ASSERT_FALSE(res_op.ok());
ASSERT_EQ("Error with filter field `id`: Filter value cannot be empty.", res_op.error());
+ res_op = coll1->search("*", {}, "id: ``", {}, sort_fields, {0}, 10, 1, FREQUENCY, {true});
+ ASSERT_FALSE(res_op.ok());
+ ASSERT_EQ("Error with filter field `id`: Filter value cannot be empty.", res_op.error());
+
// when no IDs exist
results = coll1->search("*",
{}, "id: [1000] && num_employees: <300",