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

Add validation and test for empty alter payload.

Kishore Nallanf6108feec5c1
diff --git a/src/core_api.cpp b/src/core_api.cpp
index 8634aa21..0cc9e496 100644
--- a/src/core_api.cpp
+++ b/src/core_api.cpp
@@ -316,6 +316,12 @@ bool patch_update_collection(const std::shared_ptr<http_req>& req, const std::sh
return false;
}
+ if(req_json.empty()) {
+ res->set_400("Alter payload is empty.");
+ alter_in_progress = false;
+ return false;
+ }
+
for(auto it : req_json.items()) {
if(allowed_keys.count(it.key()) == 0) {
res->set_400("Only `fields` and `metadata` can be updated at the moment.");
diff --git a/test/core_api_utils_test.cpp b/test/core_api_utils_test.cpp
index f1424077..42109911 100644
--- a/test/core_api_utils_test.cpp
+++ b/test/core_api_utils_test.cpp
@@ -2064,4 +2064,11 @@ TEST_F(CoreAPIUtilsTest, CollectionUpdateValidation) {
req->body = alter_schema.dump();
ASSERT_FALSE(patch_update_collection(req, res));
ASSERT_EQ("{\"message\": \"Only `fields` and `metadata` can be updated at the moment.\"}", res->body);
+
+ alter_schema = R"({
+ })"_json;
+
+ req->body = alter_schema.dump();
+ ASSERT_FALSE(patch_update_collection(req, res));
+ ASSERT_EQ("{\"message\": \"Alter payload is empty.\"}", res->body);
}
\ No newline at end of file