From 95f23aead0d5e2a81bd6a1cbe20b542496543d76 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 11 May 2023 10:06:20 +0800 Subject: [PATCH 1/8] fix white BOX Opinion Signed-off-by: Jeremyzz --- .../src/common/include/json_common.h | 8 +- .../src/common/src/collection_option.cpp | 2 +- .../src/common/src/db_config.cpp | 2 +- .../src/common/src/json_common.cpp | 96 ++++++++++--------- .../src/executor/document/document_check.cpp | 4 +- .../src/interface/include/collection.h | 2 +- .../src/interface/include/result_set.h | 2 +- .../src/interface/src/collection.cpp | 4 +- .../src/interface/src/document_store.cpp | 10 +- .../src/interface/src/result_set.cpp | 12 +-- .../src/oh_adapter/include/json_object.h | 8 +- .../oh_adapter/include/kv_store_executor.h | 2 +- .../src/oh_adapter/src/json_object.cpp | 24 ++--- .../src/sqlite_store_executor_impl.cpp | 2 +- .../src/sqlite_store_executor_impl.h | 2 +- .../unittest/api/documentdb_delete_test.cpp | 6 +- .../unittest/api/documentdb_find_test.cpp | 2 +- 17 files changed, 98 insertions(+), 90 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/json_common.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/json_common.h index fec8d218..cc522e24 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/json_common.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/json_common.h @@ -29,8 +29,8 @@ public: JsonCommon() = default; ~JsonCommon(); - static ValueObject GetValueByFiled(JsonObject &node, const std::string &filed); - static ValueObject GetValueByFiled(JsonObject &node, const std::string &filed, bool &isFiledExist); + static ValueObject GetValueByField(JsonObject &node, const std::string &field); + static ValueObject GetValueByField(JsonObject &node, const std::string &field, bool &isFieldExist); static bool CheckJsonField(JsonObject &node); static bool CheckProjectionField(JsonObject &node, int &errCode); static int ParseNode(JsonObject &Node, std::vector singlePath, @@ -44,8 +44,8 @@ public: private: static bool JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, const JsonObject &item, int &isAlreadyMatched, bool &isCollapse, int &isMatchFlag); - static bool CheckNode(JsonObject &Node, std::set filedSet, bool &errFlag); - static bool CheckProjectionNode(JsonObject &Node, std::set filedSet, bool &errFlag, + static bool CheckNode(JsonObject &Node, std::set fieldSet, bool &errFlag); + static bool CheckProjectionNode(JsonObject &Node, std::set fieldSet, bool &errFlag, bool isFirstFloor, int &errCode); static void CheckLeafNode(const JsonObject &Node, std::vector &leafValue); static bool IsArrayMatch(const JsonObject &src, const JsonObject &target, int &isAlreadyMatched); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/collection_option.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/collection_option.cpp index 7f34d765..324a2931 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/collection_option.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/collection_option.cpp @@ -30,7 +30,7 @@ int CheckConfigValid(const JsonObject &config) { JsonObject child = config.GetChild(); while (!child.IsNull()) { - std::string fieldName = child.GetItemFiled(); + std::string fieldName = child.GetItemField(); if (strcmp(OPT_MAX_DOC, fieldName.c_str()) != 0) { GLOGE("Invalid collection config."); return -E_INVALID_CONFIG_VALUE; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/db_config.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/db_config.cpp index 745d15b8..e800910f 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/db_config.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/db_config.cpp @@ -124,7 +124,7 @@ int CheckConfigValid(const JsonObject &config) { JsonObject child = config.GetChild(); while (!child.IsNull()) { - std::string fieldName = child.GetItemFiled(); + std::string fieldName = child.GetItemField(); bool isSupport = false; for (int i = 0; i < DB_CONFIG_SIZE; i++) { if (strcmp(DB_CONFIG[i], fieldName.c_str()) == 0) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp index 6382a49a..6d1d5294 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp @@ -22,10 +22,10 @@ #include "securec.h" namespace DocumentDB { -ValueObject JsonCommon::GetValueByFiled(JsonObject &node, const std::string &filed) +ValueObject JsonCommon::GetValueByField(JsonObject &node, const std::string &field) { while (!node.IsNull()) { - if (node.GetItemFiled() == filed) { + if (node.GetItemField() == field) { auto itemValue = node.GetItemValue(); return itemValue; } @@ -38,22 +38,22 @@ ValueObject JsonCommon::GetValueByFiled(JsonObject &node, const std::string &fil return ValueObject(); } -ValueObject JsonCommon::GetValueByFiled(JsonObject &node, const std::string &filed, bool &isFiledExist) +ValueObject JsonCommon::GetValueByField(JsonObject &node, const std::string &field, bool &isFieldExist) { while (!node.IsNull()) { - if (node.GetItemFiled() == filed) { + if (node.GetItemField() == field) { auto itemValue = node.GetItemValue(); - isFiledExist = true; + isFieldExist = true; return itemValue; } if (node.GetNext().IsNull()) { - isFiledExist = false; + isFieldExist = false; return ValueObject(); } auto nodeNew = node.GetNext(); node = nodeNew; } - isFiledExist = false; + isFieldExist = false; return ValueObject(); } @@ -84,7 +84,7 @@ std::vector JsonCommon::GetLeafValue(const JsonObject &node) return leafValue; } -bool JsonCommon::CheckNode(JsonObject &node, std::set filedSet, bool &errFlag) +bool JsonCommon::CheckNode(JsonObject &node, std::set fieldSet, bool &errFlag) { if (!errFlag) { return false; @@ -92,12 +92,16 @@ bool JsonCommon::CheckNode(JsonObject &node, std::set filedSet, boo std::string fieldName; if (!node.IsNull()) { int ret = 0; - fieldName = node.GetItemFiled(ret); - if (filedSet.find(fieldName) == filedSet.end()) { - if (ret == E_OK) { - filedSet.insert(fieldName); + bool isFieldNameExist = true; + fieldName = node.GetItemField(ret); + if (ret != E_OK) { + isFieldNameExist = false; + } + if (fieldSet.find(fieldName) == fieldSet.end()) { + if (isFieldNameExist) { + fieldSet.insert(fieldName); } - if (ret == E_OK && fieldName.empty()) { + if (isFieldNameExist && fieldName.empty()) { errFlag = false; return false; } @@ -118,24 +122,28 @@ bool JsonCommon::CheckNode(JsonObject &node, std::set filedSet, boo } if (!node.GetChild().IsNull()) { auto nodeNew = node.GetChild(); - std::set newFiledSet; - CheckNode(nodeNew, newFiledSet, errFlag); + std::set newFieldSet; + if (!CheckNode(nodeNew, newFieldSet, errFlag)) { + return false; + } } if (!node.GetNext().IsNull()) { auto nodeNew = node.GetNext(); - CheckNode(nodeNew, filedSet, errFlag); + if (!CheckNode(nodeNew, fieldSet, errFlag)) { + return false; + } } return errFlag; } bool JsonCommon::CheckJsonField(JsonObject &jsonObj) { - std::set filedSet; + std::set fieldSet; bool errFlag = true; - return CheckNode(jsonObj, filedSet, errFlag); + return CheckNode(jsonObj, fieldSet, errFlag); } -bool JsonCommon::CheckProjectionNode(JsonObject &node, std::set filedSet, bool &errFlag, +bool JsonCommon::CheckProjectionNode(JsonObject &node, std::set fieldSet, bool &errFlag, bool isFirstFloor, int &errCode) { if (!errFlag) { @@ -144,14 +152,14 @@ bool JsonCommon::CheckProjectionNode(JsonObject &node, std::set fil std::string fieldName; if (!node.IsNull()) { int ret = 0; - fieldName = node.GetItemFiled(ret); + fieldName = node.GetItemField(ret); if (fieldName.empty()) { errCode = -E_INVALID_ARGS; errFlag = false; return false; } - if (filedSet.find(fieldName) == filedSet.end() && ret == E_OK) { - filedSet.insert(fieldName); + if (fieldSet.find(fieldName) == fieldSet.end() && ret == E_OK) { + fieldSet.insert(fieldName); } else { errCode = -E_INVALID_JSON_FORMAT; errFlag = false; @@ -173,22 +181,22 @@ bool JsonCommon::CheckProjectionNode(JsonObject &node, std::set fil } if (!node.GetChild().IsNull()) { auto nodeNew = node.GetChild(); - std::set newFiledSet; - CheckProjectionNode(nodeNew, newFiledSet, errFlag, false, errCode); + std::set newFieldSet; + CheckProjectionNode(nodeNew, newFieldSet, errFlag, false, errCode); } if (!node.GetNext().IsNull()) { auto nodeNew = node.GetNext(); - CheckProjectionNode(nodeNew, filedSet, errFlag, isFirstFloor, errCode); + CheckProjectionNode(nodeNew, fieldSet, errFlag, isFirstFloor, errCode); } return errFlag; } bool JsonCommon::CheckProjectionField(JsonObject &jsonObj, int &errCode) { - std::set filedSet; + std::set fieldSet; bool errFlag = true; bool isFirstFloor = true; - return CheckProjectionNode(jsonObj, filedSet, errFlag, isFirstFloor, errCode); + return CheckProjectionNode(jsonObj, fieldSet, errFlag, isFirstFloor, errCode); } int JsonCommon::ParseNode(JsonObject &node, std::vector singlePath, @@ -198,8 +206,8 @@ int JsonCommon::ParseNode(JsonObject &node, std::vector singlePath, int insertCount = 0; if (isFirstFloor) { std::string tempParseName; - std::vector allFiledsName; - std::string priFieldName = node.GetItemFiled(); + std::vector allFieldsName; + std::string priFieldName = node.GetItemField(); for (size_t j = 0; j < priFieldName.size(); j++) { if (priFieldName[j] != '.') { tempParseName += priFieldName[j]; @@ -209,19 +217,19 @@ int JsonCommon::ParseNode(JsonObject &node, std::vector singlePath, (priFieldName[j] == '.' && j == priFieldName.size() - 1)) { return -E_INVALID_ARGS; } - allFiledsName.emplace_back(tempParseName); + allFieldsName.emplace_back(tempParseName); insertCount++; tempParseName.clear(); } } - singlePath.insert(singlePath.end(), allFiledsName.begin(), allFiledsName.end()); + singlePath.insert(singlePath.end(), allFieldsName.begin(), allFieldsName.end()); } else { - std::vector allFiledsName; - allFiledsName.emplace_back(node.GetItemFiled()); + std::vector allFieldsName; + allFieldsName.emplace_back(node.GetItemField()); insertCount++; - singlePath.insert(singlePath.end(), allFiledsName.begin(), allFiledsName.end()); + singlePath.insert(singlePath.end(), allFieldsName.begin(), allFieldsName.end()); } - if (!node.GetChild().IsNull() && node.GetChild().GetItemFiled() != "") { + if (!node.GetChild().IsNull() && node.GetChild().GetItemField() != "") { auto nodeNew = node.GetChild(); ParseNode(nodeNew, singlePath, resultPath, false); } else { @@ -294,7 +302,7 @@ void JsonObjectIterator(const JsonObject &obj, JsonFieldPath path, JsonObject child = obj.GetChild(); while (!child.IsNull()) { JsonFieldPath childPath = path; - childPath.push_back(child.GetItemFiled()); + childPath.push_back(child.GetItemField()); if (AppendFoo != nullptr && AppendFoo(childPath, obj, child)) { JsonObjectIterator(child, childPath, AppendFoo); } @@ -308,7 +316,7 @@ void JsonObjectIterator(const JsonObject &obj, JsonFieldPath path, JsonObject child = obj.GetChild(); while (!child.IsNull()) { JsonFieldPath childPath = path; - childPath.push_back(child.GetItemFiled()); + childPath.push_back(child.GetItemField()); if (MatchFoo != nullptr && MatchFoo(childPath, child)) { JsonObjectIterator(child, childPath, MatchFoo); } @@ -323,7 +331,7 @@ bool IsNumber(const std::string &str) }); } -bool AddSpliteFiled(const JsonObject &src, const JsonObject &item, const JsonFieldPath &itemPath, int &externErrCode) +bool AddSpliteField(const JsonObject &src, const JsonObject &item, const JsonFieldPath &itemPath, int &externErrCode) { int errCode = 0; JsonFieldPath abandonPath; @@ -401,7 +409,7 @@ bool JsonValueReplace(const JsonObject &src, const JsonFieldPath &fatherPath, co GLOGE("Find father item in source json object failed. %d", errCode); return false; } - fatherItem.ReplaceItemInObject(item.GetItemFiled().c_str(), item, errCode); + fatherItem.ReplaceItemInObject(item.GetItemField().c_str(), item, errCode); if (errCode != E_OK) { externErrCode = (externErrCode == E_OK ? errCode : externErrCode); GLOGE("Find father item in source json object failed. %d", errCode); @@ -419,8 +427,8 @@ bool JsonValueReplace(const JsonObject &src, const JsonFieldPath &fatherPath, co GLOGE("Replace falied, no data match"); return false; } - if (!item.GetItemFiled(errCode).empty()) { - fatherItem.ReplaceItemInObject(item.GetItemFiled().c_str(), item, errCode); + if (!item.GetItemField(errCode).empty()) { + fatherItem.ReplaceItemInObject(item.GetItemField().c_str(), item, errCode); if (errCode != E_OK) { return false; } @@ -514,7 +522,7 @@ int JsonCommon::Append(const JsonObject &src, const JsonObject &add, bool isRepl std::string lastFieldName = itemPath.back(); if (srcFatherItem.IsNull()) { isAddedFlag = true; - AddSpliteFiled(src, item, itemPath, externErrCode); + AddSpliteField(src, item, itemPath, externErrCode); return false; } if (errCode == E_OK) { @@ -594,13 +602,13 @@ bool JsonCommon::JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, return false; } JsonFieldPath granpaPath = itemPath; - std::string lastFiledName = granpaPath.back(); + std::string lastFieldName = granpaPath.back(); granpaPath.pop_back(); JsonObject granpaItem = src.FindItemPowerMode(granpaPath, errCode); if (granpaItem.GetType() == JsonObject::Type::JSON_ARRAY && isCollapse) { JsonObject fatherItem = granpaItem.GetChild(); while (!fatherItem.IsNull()) { - if ((fatherItem.GetObjectItem(lastFiledName, errCode) == item)) { + if ((fatherItem.GetObjectItem(lastFieldName, errCode) == item)) { isMatchFlag = true; isAlreadyMatched = 1; break; 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 7d1e3edc..4f56c2f1 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 @@ -203,7 +203,7 @@ bool CheckCommon::CheckDocument(const std::string &updateStr, int &errCode) int CheckCommon::CheckIdFormat(JsonObject &filterJson) { auto filterObjChild = filterJson.GetChild(); - auto idValue = JsonCommon::GetValueByFiled(filterObjChild, KEY_ID); + auto idValue = JsonCommon::GetValueByField(filterObjChild, KEY_ID); if (idValue.GetValueType() != ValueObject::ValueType::VALUE_STRING) { return -E_INVALID_ARGS; } @@ -216,7 +216,7 @@ int CheckCommon::CheckIdFormat(JsonObject &filterJson) int CheckCommon::CheckIdFormat(JsonObject &filterJson, bool &isIdExisit) { auto filterObjChild = filterJson.GetChild(); - ValueObject idValue = JsonCommon::GetValueByFiled(filterObjChild, KEY_ID, isIdExisit); + ValueObject idValue = JsonCommon::GetValueByField(filterObjChild, KEY_ID, isIdExisit); if ((idValue.GetValueType() == ValueObject::ValueType::VALUE_NULL) && isIdExisit == false) { return E_OK; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/collection.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/collection.h index 557f3322..2b0a982d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/collection.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/collection.h @@ -32,7 +32,7 @@ public: int PutDocument(const Key &key, const Value &document); int InsertDocument(const Key &key, const Value &document); int GetDocument(const Key &key, Value &document) const; - int GetFilededDocument(const JsonObject &filterObj, std::vector> &values) const; + int GetFieldedDocument(const JsonObject &filterObj, std::vector> &values) const; int DeleteDocument(const Key &key); int IsCollectionExists(int &errCode); int UpsertDocument(const std::string &id, const std::string &document, bool isReplace = true); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/result_set.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/result_set.h index a6a50238..28187d30 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/result_set.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/result_set.h @@ -51,7 +51,7 @@ private: std::string filter_; bool ifShowId_ = false; bool viewType_ = false; - bool ifFiled_ = false; + bool ifField_ = false; bool isOnlyId_ = false; ProjectionTree projectionTree_; std::vector> projectionPath_; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/collection.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/collection.cpp index 48c62d62..651d1ece 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/collection.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/collection.cpp @@ -71,13 +71,13 @@ int Collection::GetDocument(const Key &key, Value &document) const return executor_->GetData(name_, key, document); } -int Collection::GetFilededDocument(const JsonObject &filterObj, +int Collection::GetFieldedDocument(const JsonObject &filterObj, std::vector> &values) const { if (executor_ == nullptr) { return -E_INNER_ERROR; } - return executor_->GetFilededData(name_, filterObj, values); + return executor_->GetFieldedData(name_, filterObj, values); } int Collection::DeleteDocument(const Key &key) 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 c9153014..bb3215f3 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 @@ -176,7 +176,7 @@ int DocumentStore::UpdateDocument(const std::string &collection, const std::stri bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); if (isOnlyId) { auto filterObjChild = filterObj.GetChild(); - auto idValue = JsonCommon::GetValueByFiled(filterObjChild, KEY_ID); + auto idValue = JsonCommon::GetValueByField(filterObjChild, KEY_ID); std::string docId = idValue.GetStringValue(); std::lock_guard lock(dbMutex_); bool isCollectionExist = coll.IsCollectionExists(errCode); @@ -282,7 +282,7 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri return -E_INVALID_ARGS; } auto filterObjChild = filterObj.GetChild(); - ValueObject idValue = JsonCommon::GetValueByFiled(filterObjChild, KEY_ID); + ValueObject idValue = JsonCommon::GetValueByField(filterObjChild, KEY_ID); std::string docId = idValue.GetStringValue(); JsonObject idObj = filterObj.GetObjectItem(KEY_ID, errCode); documentObj.InsertItemObject(0, idObj); @@ -295,7 +295,7 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri } bool isIdExist; auto filterObjChild = filterObj.GetChild(); - auto idValue = JsonCommon::GetValueByFiled(filterObjChild, KEY_ID, isIdExist); + auto idValue = JsonCommon::GetValueByField(filterObjChild, KEY_ID, isIdExist); if (!isIdExist) { return -E_INVALID_ARGS; } @@ -361,7 +361,7 @@ int DocumentStore::InsertDocument(const std::string &collection, const std::stri return errCode; } auto documentObjChild = documentObj.GetChild(); - auto idValue = JsonCommon::GetValueByFiled(documentObjChild, KEY_ID); + auto idValue = JsonCommon::GetValueByField(documentObjChild, KEY_ID); std::string id = idValue.GetStringValue(); Key key(id.begin(), id.end()); Value value(document.begin(), document.end()); @@ -415,7 +415,7 @@ int DocumentStore::DeleteDocument(const std::string &collection, const std::stri } if (isOnlyId) { auto filterObjChild = filterObj.GetChild(); - auto idValue = JsonCommon::GetValueByFiled(filterObjChild, KEY_ID); + auto idValue = JsonCommon::GetValueByField(filterObjChild, KEY_ID); std::string id = idValue.GetStringValue(); Key key(id.begin(), id.end()); std::lock_guard lock(dbMutex_); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/result_set.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/result_set.cpp index f826bea5..f82f17f7 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/result_set.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/result_set.cpp @@ -47,7 +47,7 @@ int ResultSet::Init(DocumentStore *store, const std::string collectionName, cons int ResultSet::Init(DocumentStore *store, const std::string collectionName, const std::string &filter) { - ifFiled_ = true; + ifField_ = true; store_ = store; collectionName_ = collectionName; filter_ = filter; @@ -56,7 +56,7 @@ int ResultSet::Init(DocumentStore *store, const std::string collectionName, cons int ResultSet::GetNext() { - if (!ifFiled_ && index_ == 0) { + if (!ifField_ && index_ == 0) { if (isOnlyId_) { int errCode = 0; JsonObject filterObj = JsonObject::Parse(filter_, errCode, true, true); @@ -65,7 +65,7 @@ int ResultSet::GetNext() return errCode; } auto filterObjChild = filterObj.GetChild(); - auto idValue = JsonCommon::GetValueByFiled(filterObjChild, KEY_ID); + auto idValue = JsonCommon::GetValueByField(filterObjChild, KEY_ID); std::string idKey = idValue.GetStringValue(); if (idKey.empty()) { GLOGE("id is empty"); @@ -93,7 +93,7 @@ int ResultSet::GetNext() GLOGE("filter Parsed failed"); return errCode; } - errCode = coll.GetFilededDocument(filterObj, values); + errCode = coll.GetFieldedDocument(filterObj, values); if (errCode == -E_NOT_FOUND) { GLOGE("Cant get value from db"); return -E_NO_DATA; @@ -112,7 +112,7 @@ int ResultSet::GetNext() GLOGE("filter Parsed failed"); return errCode; } - errCode = coll.GetFilededDocument(filterObj, values); + errCode = coll.GetFieldedDocument(filterObj, values); if (errCode == -E_NOT_FOUND) { GLOGE("Cant get value from db"); return -E_NO_DATA; @@ -166,7 +166,7 @@ int ResultSet::CheckCutNode(JsonObject *node, std::vector singlePat GLOGE("No node to cut"); return -E_NO_DATA; } - singlePath.emplace_back(node->GetItemFiled()); + singlePath.emplace_back(node->GetItemField()); int index = 0; if (!projectionTree_.SearchTree(singlePath, index) && index == 0) { allCutPath.emplace_back(singlePath); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h index 69fc3d4e..6adebe7d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h @@ -81,12 +81,12 @@ public: ValueObject GetItemValue() const; void ReplaceItemInArray(const int &index, const JsonObject &newItem, int &errCode); - void ReplaceItemInObject(const std::string &filedName, const JsonObject &newItem, int &errCode); + void ReplaceItemInObject(const std::string &fieldName, const JsonObject &newItem, int &errCode); void SetItemValue(const ValueObject &value) const; int InsertItemObject(int which, const JsonObject &newItem); - std::string GetItemFiled() const; - std::string GetItemFiled(int &errCode) const; + std::string GetItemField() const; + std::string GetItemField(int &errCode) const; bool IsFieldExists(const JsonFieldPath &jsonPath) const; bool IsFieldExistsPowerMode(const JsonFieldPath &jsonPath) const; @@ -108,7 +108,7 @@ private: JsonObject(); int Init(const std::string &str, bool isFilter = false); int CheckJsonRepeatField(cJSON *object); - int CheckSubObj(std::set &filedSet, cJSON *subObj, int parentType); + int CheckSubObj(std::set &fieldSet, cJSON *subObj, int parentType); int GetDeep(cJSON *cjson); int CheckNumber(cJSON *cjson, int &errCode); cJSON *cjson_ = nullptr; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/kv_store_executor.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/kv_store_executor.h index 0f3954b2..9b6533e0 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/kv_store_executor.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/kv_store_executor.h @@ -32,7 +32,7 @@ public: virtual int PutData(const std::string &collName, const Key &key, const Value &value) = 0; virtual int InsertData(const std::string &collName, const Key &key, const Value &value) = 0; virtual int GetData(const std::string &collName, const Key &key, Value &value) const = 0; - virtual int GetFilededData(const std::string &collName, const JsonObject &filterObj, + virtual int GetFieldedData(const std::string &collName, const JsonObject &filterObj, std::vector> &values) const = 0; virtual int DelData(const std::string &collName, const Key &key) = 0; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp index 201fb391..625d39f5 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp @@ -229,10 +229,10 @@ int JsonObject::CheckJsonRepeatField(cJSON *object) if (type != cJSON_Object && type != cJSON_Array) { return ret; } - std::set filedSet; + std::set fieldSet; cJSON *subObj = object->child; while (subObj != nullptr) { - ret = CheckSubObj(filedSet, subObj, type); + ret = CheckSubObj(fieldSet, subObj, type); if (ret != E_OK) { break; } @@ -241,7 +241,7 @@ int JsonObject::CheckJsonRepeatField(cJSON *object) return ret; } -int JsonObject::CheckSubObj(std::set &filedSet, cJSON *subObj, int parentType) +int JsonObject::CheckSubObj(std::set &fieldSet, cJSON *subObj, int parentType) { if (subObj == nullptr) { return -E_INVALID_ARGS; @@ -261,8 +261,8 @@ int JsonObject::CheckSubObj(std::set &filedSet, cJSON *subObj, int if (fieldName.empty()) { return -E_INVALID_JSON_FORMAT; } - if (filedSet.find(fieldName) == filedSet.end()) { - filedSet.insert(fieldName); + if (fieldSet.find(fieldName) == fieldSet.end()) { + fieldSet.insert(fieldName); } else { ret = -E_INVALID_JSON_FORMAT; } @@ -368,7 +368,7 @@ int JsonObject::AddItemToObject(const JsonObject &item) } cJSON *cpoyItem = cJSON_Duplicate(item.cjson_, true); - cJSON_AddItemToObject(cjson_, item.GetItemFiled().c_str(), cpoyItem); + cJSON_AddItemToObject(cjson_, item.GetItemField().c_str(), cpoyItem); return E_OK; } @@ -452,16 +452,16 @@ ValueObject JsonObject::GetItemValue() const return value; } -void JsonObject::ReplaceItemInObject(const std::string &filedName, const JsonObject &newItem, int &errCode) +void JsonObject::ReplaceItemInObject(const std::string &fieldName, const JsonObject &newItem, int &errCode) { if (!newItem.IsNull() || !this->IsNull()) { if (this->GetType() == JsonObject::Type::JSON_OBJECT) { - if (!(this->GetObjectItem(filedName.c_str(), errCode).IsNull())) { + if (!(this->GetObjectItem(fieldName.c_str(), errCode).IsNull())) { cJSON *copyItem = cJSON_Duplicate(newItem.cjson_, true); - cJSON_ReplaceItemInObjectCaseSensitive(this->cjson_, filedName.c_str(), copyItem); + cJSON_ReplaceItemInObjectCaseSensitive(this->cjson_, fieldName.c_str(), copyItem); } else { cJSON *copyItem = cJSON_Duplicate(newItem.cjson_, true); - cJSON_AddItemToObject(this->cjson_, filedName.c_str(), copyItem); + cJSON_AddItemToObject(this->cjson_, fieldName.c_str(), copyItem); } } } @@ -508,7 +508,7 @@ int JsonObject::InsertItemObject(int which, const JsonObject &newItem) return E_OK; } -std::string JsonObject::GetItemFiled() const +std::string JsonObject::GetItemField() const { if (cjson_ == nullptr) { return ""; @@ -532,7 +532,7 @@ std::string JsonObject::GetItemFiled() const } } -std::string JsonObject::GetItemFiled(int &errCode) const +std::string JsonObject::GetItemField(int &errCode) const { if (cjson_ == nullptr) { errCode = E_INVALID_ARGS; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.cpp index c7f262df..fbd0fd84 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.cpp @@ -177,7 +177,7 @@ int SqliteStoreExecutor::GetData(const std::string &collName, const Key &key, Va return innerErrorCode; } -int SqliteStoreExecutor::GetFilededData(const std::string &collName, const JsonObject &filterObj, +int SqliteStoreExecutor::GetFieldedData(const std::string &collName, const JsonObject &filterObj, std::vector> &values) const { if (dbHandle_ == nullptr) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.h index f3c0fede..532d4b91 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.h @@ -39,7 +39,7 @@ public: int PutData(const std::string &collName, const Key &key, const Value &value) override; int InsertData(const std::string &collName, const Key &key, const Value &value) override; int GetData(const std::string &collName, const Key &key, Value &value) const override; - int GetFilededData(const std::string &collName, const JsonObject &filterObj, + int GetFieldedData(const std::string &collName, const JsonObject &filterObj, std::vector> &values) const override; int DelData(const std::string &collName, const Key &key) override; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_delete_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_delete_test.cpp index c4281902..a41d3557 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_delete_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_delete_test.cpp @@ -161,7 +161,7 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest002, TestSize.Level1) /** * @tc.name: DocumentDelete003 - * @tc.desc: Delete with filter which has more than one fileds. + * @tc.desc: Delete with filter which has more than one fields. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao @@ -169,7 +169,7 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest002, TestSize.Level1) HWTEST_F(DocumentDeleteApiTest, DeleteDBTest003, TestSize.Level1) { /** - * @tc.steps:step1. Delete with filter which has more than one fileds. + * @tc.steps:step1. Delete with filter which has more than one fields. * @tc.expected: step1. GRD_INVALID_ARGS */ const char *filter = "{\"_id\" : \"1\", \"age\" : 15}"; @@ -284,7 +284,7 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest007, TestSize.Level1) HWTEST_F(DocumentDeleteApiTest, DeleteDBTest008, TestSize.Level1) { /** - * @tc.steps:step1. Delete with filter which has more than one fileds. + * @tc.steps:step1. Delete with filter which has more than one fields. * @tc.expected: step1. GRD_INVALID_ARGS */ const char *filter = "{\"_id\" : \"1\"}"; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_find_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_find_test.cpp index 05efa28e..285a5fbd 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_find_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_find_test.cpp @@ -1022,7 +1022,7 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest036, TestSize.Level1) /** * @tc.name: DocumentFindApiTest037 - * @tc.desc: Test filed with different value. + * @tc.desc: Test field with different value. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao -- Gitee From b868bf40fdcf2967ad9c0bfd97157325c39fa0bc Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 11 May 2023 10:10:42 +0800 Subject: [PATCH 2/8] fix white box opinion 2 Signed-off-by: Jeremyzz --- .../gaussdb_rd_simple/src/common/src/json_common.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp index 6d1d5294..169789eb 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp @@ -182,11 +182,15 @@ bool JsonCommon::CheckProjectionNode(JsonObject &node, std::set fie if (!node.GetChild().IsNull()) { auto nodeNew = node.GetChild(); std::set newFieldSet; - CheckProjectionNode(nodeNew, newFieldSet, errFlag, false, errCode); + if (!CheckProjectionNode(nodeNew, newFieldSet, errFlag, false, errCode)) { + return false; + } } if (!node.GetNext().IsNull()) { auto nodeNew = node.GetNext(); - CheckProjectionNode(nodeNew, fieldSet, errFlag, isFirstFloor, errCode); + if (!CheckProjectionNode(nodeNew, fieldSet, errFlag, isFirstFloor, errCode)) { + return false; + } } return errFlag; } -- Gitee From 0694dcc2280e06be52d30e3f4f51785ea043a998 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 11 May 2023 11:05:10 +0800 Subject: [PATCH 3/8] fix write box code check Signed-off-by: Jeremyzz --- .../src/common/src/json_common.cpp | 60 +++++++++++-------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp index 169789eb..51252642 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp @@ -235,7 +235,11 @@ int JsonCommon::ParseNode(JsonObject &node, std::vector singlePath, } if (!node.GetChild().IsNull() && node.GetChild().GetItemField() != "") { auto nodeNew = node.GetChild(); - ParseNode(nodeNew, singlePath, resultPath, false); + int ret = E_OK; + ret = ParseNode(nodeNew, singlePath, resultPath, false); + if (ret != E_OK) { + return ret; + } } else { resultPath.emplace_back(singlePath); } @@ -341,8 +345,11 @@ bool AddSpliteField(const JsonObject &src, const JsonObject &item, const JsonFie JsonFieldPath abandonPath; JsonFieldPath hitPath = itemPath; while (!hitPath.empty()) { - JsonObject srcFatherItem = src.FindItem(hitPath, errCode); abandonPath.emplace_back(hitPath.back()); + JsonObject srcFatherItem = src.FindItem(hitPath, errCode); + if (errCode != -E_JSON_PATH_NOT_EXISTS) { + break; + } if (!srcFatherItem.IsNull()) { break; } @@ -352,33 +359,35 @@ bool AddSpliteField(const JsonObject &src, const JsonObject &item, const JsonFie JsonFieldPath preHitPath = hitPath; preHitPath.pop_back(); JsonObject preHitItem = src.FindItem(preHitPath, errCode); - JsonObject hitItem = preHitItem.GetObjectItem(hitPath.back(), errCode); - if (!abandonPath.empty()) { - abandonPath.pop_back(); - } - if (!hitItem.IsNull()) { - JsonFieldPath newHitPath; - for (int i = abandonPath.size() - 1; i > -1; i--) { - if (hitItem.GetType() != JsonObject::Type::JSON_OBJECT) { - GLOGE("Add collapse item to object failed, path not exist."); - externErrCode = -E_DATA_CONFLICT; - return false; - } - if (IsNumber(abandonPath[i])) { - externErrCode = -E_DATA_CONFLICT; - return false; + JsonObject hitItem = preHitItem.GetObjectItem(hitPath.back(), errCode); // if FindItem errCode is not E_OK, GetObjectItem errCode should be E_NOT_FOUND + if (errCode != E_NOT_FOUND) { + if (!abandonPath.empty()) { + abandonPath.pop_back(); + } + if (!hitItem.IsNull()) { + JsonFieldPath newHitPath; + for (int i = abandonPath.size() - 1; i > -1; i--) { + if (hitItem.GetType() != JsonObject::Type::JSON_OBJECT) { + GLOGE("Add collapse item to object failed, path not exist."); + externErrCode = -E_DATA_CONFLICT; + return false; + } + if (IsNumber(abandonPath[i])) { + externErrCode = -E_DATA_CONFLICT; + return false; + } + (i == 0) ? errCode = hitItem.AddItemToObject(abandonPath[i], item) + : errCode = hitItem.AddItemToObject(abandonPath[i]); + externErrCode = (externErrCode == E_OK ? errCode : externErrCode); } - (i == 0) ? errCode = hitItem.AddItemToObject(abandonPath[i], item) - : errCode = hitItem.AddItemToObject(abandonPath[i]); - externErrCode = (externErrCode == E_OK ? errCode : externErrCode); - newHitPath.emplace_back(abandonPath[i]); - hitItem = hitItem.FindItem(newHitPath, errCode); - newHitPath.pop_back(); + return false; } - return false; } } JsonObject hitItem = src.FindItem(hitPath, errCode); + if (errCode != E_OK) { + return false; + } JsonFieldPath newHitPath; for (int i = abandonPath.size() - 1; i > -1; i--) { if (hitItem.GetType() != JsonObject::Type::JSON_OBJECT) { @@ -395,6 +404,9 @@ bool AddSpliteField(const JsonObject &src, const JsonObject &item, const JsonFie externErrCode = (externErrCode == E_OK ? errCode : externErrCode); newHitPath.emplace_back(abandonPath[i]); hitItem = hitItem.FindItem(newHitPath, errCode); + if (errCode != E_OK) { + return false; + } newHitPath.pop_back(); } return false; -- Gitee From 213fe2645070747cc5ff07fc6cb762ff0da48afd Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 11 May 2023 11:08:32 +0800 Subject: [PATCH 4/8] fix white box Signed-off-by: Jeremyzz --- .../gaussdb_rd_simple/src/common/src/json_common.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp index 51252642..555261d5 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp @@ -579,11 +579,11 @@ bool JsonCommon::isValueEqual(const ValueObject &srcValue, const ValueObject &ta case ValueObject::ValueType::VALUE_NULL: return true; case ValueObject::ValueType::VALUE_BOOL: - return srcValue.GetBoolValue() == targetValue.GetBoolValue() ? true : false; + return srcValue.GetBoolValue() == targetValue.GetBoolValue(); case ValueObject::ValueType::VALUE_NUMBER: - return srcValue.GetDoubleValue() == targetValue.GetDoubleValue() ? true : false; + return srcValue.GetDoubleValue() == targetValue.GetDoubleValue(); case ValueObject::ValueType::VALUE_STRING: - return srcValue.GetStringValue() == targetValue.GetStringValue() ? true : false; + return srcValue.GetStringValue() == targetValue.GetStringValue(); } } return false; -- Gitee From 9133b049a2f3eeecf872abc08281dc23c3ff9910 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 11 May 2023 11:30:55 +0800 Subject: [PATCH 5/8] fix white box check Signed-off-by: Jeremyzz --- .../src/common/src/json_common.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp index 555261d5..cf7c143a 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp @@ -359,7 +359,8 @@ bool AddSpliteField(const JsonObject &src, const JsonObject &item, const JsonFie JsonFieldPath preHitPath = hitPath; preHitPath.pop_back(); JsonObject preHitItem = src.FindItem(preHitPath, errCode); - JsonObject hitItem = preHitItem.GetObjectItem(hitPath.back(), errCode); // if FindItem errCode is not E_OK, GetObjectItem errCode should be E_NOT_FOUND + JsonObject hitItem = preHitItem.GetObjectItem(hitPath.back(), + errCode); // if FindItem errCode is not E_OK, GetObjectItem errCode should be E_NOT_FOUND if (errCode != E_NOT_FOUND) { if (!abandonPath.empty()) { abandonPath.pop_back(); @@ -597,7 +598,7 @@ bool JsonCommon::IsArrayMatch(const JsonObject &src, const JsonObject &target, i int errCode = 0; while (!srcChild.IsNull()) { if (srcChild.GetType() == JsonObject::Type::JSON_OBJECT && target.GetType() == JsonObject::Type::JSON_OBJECT && - (IsJsonNodeMatch(srcChild, target, errCode))) { + (IsJsonNodeMatch(srcChild, target, errCode))) { // The return value reflects the value of errCode isMatch = true; isAlreadyMatched = 1; break; @@ -612,7 +613,7 @@ bool JsonCommon::JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, { int errCode; JsonObject srcItem = src.FindItemPowerMode(itemPath, errCode); - if (srcItem == item) { + if (errCode != -E_JSON_PATH_NOT_EXISTS && srcItem == item) { isMatchFlag = true; isAlreadyMatched = 1; return false; @@ -621,10 +622,10 @@ bool JsonCommon::JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, std::string lastFieldName = granpaPath.back(); granpaPath.pop_back(); JsonObject granpaItem = src.FindItemPowerMode(granpaPath, errCode); - if (granpaItem.GetType() == JsonObject::Type::JSON_ARRAY && isCollapse) { + if (errCode != -E_JSON_PATH_NOT_EXISTS && granpaItem.GetType() == JsonObject::Type::JSON_ARRAY && isCollapse) { JsonObject fatherItem = granpaItem.GetChild(); while (!fatherItem.IsNull()) { - if ((fatherItem.GetObjectItem(lastFieldName, errCode) == item)) { + if ((fatherItem.GetObjectItem(lastFieldName, errCode) == item)) { // this errCode is always E_OK isMatchFlag = true; isAlreadyMatched = 1; break; @@ -681,6 +682,9 @@ bool JsonCommon::IsJsonNodeMatch(const JsonObject &src, const JsonObject &target return JsonEqualJudge(itemPath, src, item, isAlreadyMatched, isCollapse, isMatchFlag); } else { JsonObject srcItem = src.FindItemPowerMode(itemPath, errCode); + if (errCode != E_OK) { + return false; + } if (srcItem.GetType() == JsonObject::Type::JSON_ARRAY) { return JsonEqualJudge(itemPath, src, item, isAlreadyMatched, isCollapse, isMatchFlag); } -- Gitee From 6e8a9b1f6416837dfa608a6917b3d3f22c8a12ab Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 11 May 2023 11:36:43 +0800 Subject: [PATCH 6/8] fix white box check Signed-off-by: Jeremyzz --- .../src/executor/document/document_check.cpp | 67 +------------------ .../src/executor/document/document_check.h | 3 - 2 files changed, 3 insertions(+), 67 deletions(-) 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 4f56c2f1..4a3c8a4a 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 @@ -75,30 +75,6 @@ bool CheckCommon::CheckCollectionName(const std::string &collectionName, std::st return true; } -int CheckCommon::CheckFilter(JsonObject &filterObj) -{ - if (filterObj.GetDeep() > JSON_DEEP_MAX) { - GLOGE("filter's json deep is deeper than JSON_DEEP_MAX"); - return -E_INVALID_ARGS; - } - if (!filterObj.GetChild().IsNull()) { - auto filterObjChild = filterObj.GetChild(); - if (!JsonCommon::CheckJsonField(filterObjChild)) { - GLOGE("filter json field format is illegal"); - return -E_INVALID_ARGS; - } - } - int ret = CheckIdFormat(filterObj); - if (ret != E_OK) { - GLOGE("Filter Id format is illegal"); - return ret; - } - if (!filterObj.GetChild().GetNext().IsNull()) { - return -E_INVALID_ARGS; - } - return E_OK; -} - int CheckCommon::CheckFilter(JsonObject &filterObj, bool &isOnlyId, std::vector> &filterPath) { for (size_t i = 0; i < filterPath.size(); i++) { @@ -140,31 +116,6 @@ int CheckCommon::CheckFilter(JsonObject &filterObj, bool &isOnlyId, std::vector< return E_OK; } -bool CheckCommon::CheckFilter(const std::string &filter, std::string &idStr, int &errCode) -{ - if (filter.empty()) { - errCode = -E_INVALID_ARGS; - GLOGE("Check filter invalid. %d", errCode); - return false; - } - - JsonObject filterObject = JsonObject::Parse(filter, errCode, true, true); - if (errCode != E_OK) { - GLOGE("Parse filter failed. %d", errCode); - return false; - } - - JsonObject filterId = filterObject.GetObjectItem("_id", errCode); - if (errCode != E_OK || filterId.GetItemValue().GetValueType() != ValueObject::ValueType::VALUE_STRING) { - GLOGE("Check filter '_id' not found or type not string."); - errCode = -E_INVALID_ARGS; - return false; - } - - idStr = filterId.GetItemValue().GetStringValue(); - return true; -} - bool CheckCommon::CheckDocument(const std::string &updateStr, int &errCode) { if (updateStr.empty()) { @@ -200,19 +151,6 @@ bool CheckCommon::CheckDocument(const std::string &updateStr, int &errCode) return true; } -int CheckCommon::CheckIdFormat(JsonObject &filterJson) -{ - auto filterObjChild = filterJson.GetChild(); - auto idValue = JsonCommon::GetValueByField(filterObjChild, KEY_ID); - if (idValue.GetValueType() != ValueObject::ValueType::VALUE_STRING) { - return -E_INVALID_ARGS; - } - if (idValue.GetStringValue().length() + 1 > MAX_ID_LENS) { // with '\0 - return -E_OVER_LIMIT; - } - return E_OK; -} - int CheckCommon::CheckIdFormat(JsonObject &filterJson, bool &isIdExisit) { auto filterObjChild = filterJson.GetChild(); @@ -235,8 +173,9 @@ int CheckCommon::CheckDocument(JsonObject &documentObj) GLOGE("documentObj's json deep is deeper than JSON_DEEP_MAX"); return -E_INVALID_ARGS; } - int ret = CheckIdFormat(documentObj); - if (ret != E_OK) { + bool isIdExist = true; + int ret = CheckIdFormat(documentObj, isIdExist); + if (!isIdExist || ret != E_OK) { GLOGE("Document Id format is illegal"); return ret; } 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 3e5b984f..c9b94350 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 @@ -29,10 +29,7 @@ public: ~CheckCommon() = default; static bool CheckCollectionName(const std::string &collectionName, std::string &formattedName, int &errCode); - static int CheckFilter(JsonObject &document); static int CheckFilter(JsonObject &document, bool &isOnlyId, std::vector> &filterPath); - static bool CheckFilter(const std::string &filter, std::string &idStr, int &errCode); - static int CheckIdFormat(JsonObject &data); static int CheckIdFormat(JsonObject &data, bool &isIdExisit); static int CheckDocument(JsonObject &document); static int CheckUpdata(JsonObject &updata, std::vector> &path); -- Gitee From fd9f4752c6dd59eed8e64ab4f518c4636e45d5a0 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 11 May 2023 11:50:40 +0800 Subject: [PATCH 7/8] fix white box Signed-off-by: Jeremyzz --- .../gaussdb_rd_simple/src/common/src/json_common.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp index cf7c143a..69ebed1d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp @@ -537,12 +537,11 @@ int JsonCommon::Append(const JsonObject &src, const JsonObject &add, bool isRepl } JsonObject srcFatherItem = src.FindItem(fatherPath, errCode); std::string lastFieldName = itemPath.back(); - if (srcFatherItem.IsNull()) { + if (errCode != E_OK) { isAddedFlag = true; AddSpliteField(src, item, itemPath, externErrCode); return false; - } - if (errCode == E_OK) { + } else { if (isCollapse && (!IsNumber(itemPath.back()) || srcFatherItem.GetType() == JsonObject::Type::JSON_ARRAY)) { errCode = srcFatherItem.AddItemToObject(itemPath.back(), item); @@ -625,7 +624,7 @@ bool JsonCommon::JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, if (errCode != -E_JSON_PATH_NOT_EXISTS && granpaItem.GetType() == JsonObject::Type::JSON_ARRAY && isCollapse) { JsonObject fatherItem = granpaItem.GetChild(); while (!fatherItem.IsNull()) { - if ((fatherItem.GetObjectItem(lastFieldName, errCode) == item)) { // this errCode is always E_OK + if ((fatherItem.GetObjectItem(lastFieldName, errCode) == item)) { // this errCode is always E_OK isMatchFlag = true; isAlreadyMatched = 1; break; -- Gitee From a3a14543e84b54abcddf77b4ff8cb0c9a619a608 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 11 May 2023 15:25:16 +0800 Subject: [PATCH 8/8] fix code check opinion Signed-off-by: Jeremyzz --- .../gaussdb_rd_simple/src/common/src/json_common.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp index 69ebed1d..e9267988 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp @@ -100,10 +100,10 @@ bool JsonCommon::CheckNode(JsonObject &node, std::set fieldSet, boo if (fieldSet.find(fieldName) == fieldSet.end()) { if (isFieldNameExist) { fieldSet.insert(fieldName); - } - if (isFieldNameExist && fieldName.empty()) { - errFlag = false; - return false; + if (fieldName.empty()) { + errFlag = false; + return false; + } } } else { errFlag = false; -- Gitee