Skip to content

Commit 6c615cc

Browse files
committed
fix: add form data checking
1 parent ad3785d commit 6c615cc

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/lse/api/helper/CustomFormWrapper.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "CustomFormWrapper.h"
22

3+
#include "nlohmann/json.hpp"
4+
35
namespace lse::form {
46

57
CustomFormResult
@@ -24,11 +26,18 @@ CustomFormWrapper::convertResult(std::optional<std::string> const& result, std::
2426
CustomFormResult
2527
CustomFormWrapper::convertResult(std::optional<std::string> const& result, nlohmann::ordered_json const& formData) {
2628
if (!result) return {};
29+
auto type = formData.find("type");
30+
auto content = formData.find("content");
31+
if (content == formData.end() || type == formData.end() || *type != "custom") {
32+
return nlohmann::ordered_json::parse(*result);
33+
}
2734
std::vector<int> resultIndices{};
2835
int index = 0;
2936
std::set<std::string> fillNullTypes({"header", "label", "divider"});
30-
for (auto& data : formData["content"]) {
31-
if (fillNullTypes.contains(data["type"])) resultIndices.emplace_back(-1);
37+
for (auto& data : *content) {
38+
auto type = data.find("type");
39+
if (type == data.end()) return {};
40+
if (fillNullTypes.contains(*type)) resultIndices.emplace_back(-1);
3241
else resultIndices.emplace_back(index++);
3342
}
3443
return convertResult(result, resultIndices);

src/lse/api/helper/CustomFormWrapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "ll/api/form/CustomForm.h"
44
#include "ll/api/form/FormBase.h"
5-
#include "nlohmann/json.hpp"
5+
#include "nlohmann/json_fwd.hpp"
66

77
namespace lse::form {
88

0 commit comments

Comments
 (0)