This commit is contained in:
Jonathan Steininger 2025-05-12 13:21:18 +12:00 committed by GitHub
commit d3b5db8a3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -642,10 +642,22 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) {
anyMatch = true;
}
// parse expressions $(somevar + 2)
// parse expressions {{somevar + 2}}
// We only support single expressions for now
while (RHS.contains("{{")) {
const auto BEGIN_EXPR = RHS.find("{{");
auto firstUnescaped = RHS.find("{{");
//keep searching until the escape char is not found.
while(firstUnescaped != 0 && RHS.at(firstUnescaped - 1) == '\\'){
firstUnescaped = RHS.find("{{", firstUnescaped + 1);
//break if the next match is never found
if(firstUnescaped == std::string::npos)
break;
}
//real match was never found.
if(firstUnescaped == std::string::npos)
break;
const auto BEGIN_EXPR = firstUnescaped;
// }} doesnt need escaping. Would be invalid expression anyways.
const auto END_EXPR = RHS.find("}}", BEGIN_EXPR + 2);
if (END_EXPR != std::string::npos) {
// try to parse the expression
@ -669,6 +681,15 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) {
}
}
// Removing escape chars. -- in the future, maybe map all the chars that can be escaped.
// Right now only expression parsing has escapeable chars
for(long i = 0; i < (long)RHS.length()-(long)1; i++){
if(RHS.at(i) == '\\' && (RHS.at(i+1) == '{' || RHS.at(i+1) == '}')){
RHS.erase(i--, 1);
continue;
}
}
if (ISVARIABLE)
return parseVariable(LHS, RHS, dynamic);