mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
chore: TaskData增加OcrTask的ocrReplace合法性检查 (#11878)
* chore: TaskData增加OcrTask的ocrReplace合法性检查 * docs: 加点注释
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <meojson/json.hpp>
|
||||
#include <regex>
|
||||
|
||||
#ifdef ASST_DEBUG
|
||||
#include <queue>
|
||||
@@ -185,6 +186,20 @@ bool asst::TaskData::lazy_parse(const json::value& json)
|
||||
Log.error("Task", name, "with Count method has empty color_scales");
|
||||
validity = false;
|
||||
}
|
||||
// 用于解决 a8d68dd72df6eef1d2f8feed3883299922ec1a17 类似的潜在regex非法问题
|
||||
if (auto ocr_task = std::dynamic_pointer_cast<OcrTaskInfo>(task);
|
||||
task->algorithm == AlgorithmType::OcrDetect) {
|
||||
for (const auto& [regex, new_str] : ocr_task->replace_map) {
|
||||
try {
|
||||
std::regex _(regex);
|
||||
}
|
||||
catch (const std::regex_error& e) {
|
||||
Log.error("Task", name, "has invalid regex:", regex, ":", e.what());
|
||||
validity = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (checking_task_set.size() > MAX_CHECKING_SIZE) {
|
||||
// 生成超出上限一般是出现了会导致无限隐式生成的任务。比如 "#self@LoadingText". 这里给个警告.
|
||||
|
||||
Reference in New Issue
Block a user