Fix: [Script] Improve ScriptText validation (#11721)

The validation is now done in two steps:
 - First we get the list of parameters in the same order they used to be in encoded string
 - Then we validate the parameter types like FormatString would use them while encoding the string
This commit is contained in:
Loïc Guilloux
2024-01-18 18:06:30 +01:00
committed by GitHub
parent 28ef5146ba
commit bf4b669628
4 changed files with 87 additions and 60 deletions

View File

@@ -268,9 +268,15 @@ static void ExtractStringParams(const StringData &data, StringParamsList &params
StringParams &param = params.emplace_back();
ParsedCommandStruct pcs = ExtractCommandString(ls->english.c_str(), false);
for (const CmdStruct *cs : pcs.consuming_commands) {
if (cs == nullptr) break;
param.emplace_back(GetParamType(cs), cs->consumes);
for (auto it = pcs.consuming_commands.begin(); it != pcs.consuming_commands.end(); it++) {
if (*it == nullptr) {
/* Skip empty param unless a non empty param exist after it. */
if (std::all_of(it, pcs.consuming_commands.end(), [](auto cs) { return cs == nullptr; })) break;
param.emplace_back(StringParam::UNUSED, 1, nullptr);
continue;
}
const CmdStruct *cs = *it;
param.emplace_back(GetParamType(cs), cs->consumes, cs->cmd);
}
}
}

View File

@@ -12,6 +12,7 @@
struct StringParam {
enum ParamType {
UNUSED,
RAW_STRING,
STRING,
OTHER
@@ -19,8 +20,9 @@ struct StringParam {
ParamType type;
uint8_t consumes;
const char *cmd;
StringParam(ParamType type, uint8_t consumes) : type(type), consumes(consumes) {}
StringParam(ParamType type, uint8_t consumes, const char *cmd) : type(type), consumes(consumes), cmd(cmd) {}
};
using StringParams = std::vector<StringParam>;
using StringParamsList = std::vector<StringParams>;