diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp index 285036fc4ba7d7e609305b3cefbd1ec2604efcc2..598aceab0d0efe98a011fb7e4d91e638a66290ef 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp @@ -238,7 +238,7 @@ int CheckCommon::CheckDocument(JsonObject &documentObj) return E_OK; } -bool CheckCommon::CheckUpdata(JsonObject &updataObj, std::vector> &path) +int CheckCommon::CheckUpdata(JsonObject &updataObj, std::vector> &path) { if (updataObj.GetDeep() > JSON_DEEP_MAX) { GLOGE("projectionObj's json deep is deeper than JSON_DEEP_MAX"); @@ -248,25 +248,25 @@ bool CheckCommon::CheckUpdata(JsonObject &updataObj, std::vector JSON_DEEP_MAX) { - return false; + return -E_INVALID_ARGS;; } } bool isIdExist = true; CheckIdFormat(updataObj, isIdExist); if (isIdExist) { - return false; + return -E_INVALID_ARGS;; } - return true; + return E_OK; } bool CheckCommon::CheckProjection(JsonObject &projectionObj, std::vector> &path) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.h index d094ed42adbc655d6892dd77b6bb5197e33a8574..45d50bc10762c06e008d20eb9cdfcf13cf5be2cb 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.h @@ -35,7 +35,7 @@ public: static int CheckIdFormat(JsonObject &data); static int CheckIdFormat(JsonObject &data, bool &isIdExisit); static int CheckDocument(JsonObject &document); - static bool CheckUpdata(JsonObject &updata, std::vector> &path); + static int CheckUpdata(JsonObject &updata, std::vector> &path); static bool CheckDocument(const std::string &updateStr, int &errCode); static bool CheckProjection(JsonObject &projectionObj, std::vector> &path); }; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp index 210316d84bd4920decaeb127408fd9f8110c97fe..7511968d9213adcb44d2e960711ab5daae0c107f 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp @@ -133,9 +133,10 @@ int DocumentStore::UpdateDocument(const std::string &collection, const std::stri GLOGE("updateObj ParsePath faild"); return errCode; } - if (!CheckCommon::CheckUpdata(updateObj, allPath)) { - GLOGE("Updata format unvalid"); - return -E_INVALID_ARGS; + errCode = CheckCommon::CheckUpdata(updateObj, allPath); + if (errCode != E_OK) { + GLOGE("Updata format is illegal"); + return errCode; } } if (flags != GRD_DOC_APPEND && flags != GRD_DOC_REPLACE) { @@ -213,9 +214,10 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri if (errCode != E_OK) { return errCode; } - if (!CheckCommon::CheckUpdata(documentObj, allPath)) { - GLOGE("updata format unvalid"); - return -E_INVALID_ARGS; + errCode = CheckCommon::CheckUpdata(documentObj, allPath); + if (errCode != E_OK) { + GLOGE("UpsertDocument document format is illegal"); + return errCode; } } if (flags != GRD_DOC_APPEND && flags != GRD_DOC_REPLACE) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp index 17ff76b7b25f45d3f8ba2514a7fa7aeb6cac76fc..6f3aebb6e984d918eb52f92b1f9b990320131c6c 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp @@ -22,6 +22,7 @@ #include "grd_document/grd_document_api.h" #include "log_print.h" #include "sqlite_utils.h" +#include "cJSON.h" using namespace DocumentDB; using namespace testing::ext; @@ -257,4 +258,13 @@ HWTEST_F(DocumentDBDataTest, UpdateDataTest006, TestSize.Level0) GLOGD("UpdateDataTest006: update data with flag: %u", flag); EXPECT_EQ(GRD_UpdateDoc(g_db, g_coll, filter.c_str(), document.c_str(), flag), GRD_INVALID_ARGS); } +} + +HWTEST_F(DocumentDBDataTest, UpdateDataTest007, TestSize.Level0) +{ + const char *updateStr = R""({"field2":{"c_field":{"cc_field":{"ccc_field":{"ccc_field":[1,false,1.234e2,["hello world!"]]}}}}})""; + int result = GRD_UpdateDoc(g_db, g_coll, "{\"field\" : 2}", updateStr, 0); + int result2 = GRD_UpsertDoc(g_db, g_coll, "{\"field\" : 2}", updateStr, 0); + EXPECT_EQ(result, GRD_INVALID_ARGS); + EXPECT_EQ(result2, GRD_INVALID_ARGS); } \ No newline at end of file