Merge pull request #74 from Jovvik/main

Added escaping of `{`, `}` and `$`
This commit is contained in:
vaxerski 2022-05-22 09:38:28 +02:00 committed by GitHub
commit ba47d7950f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 6 deletions

View File

@ -158,17 +158,26 @@ std::string BarCommands::parseCommand(std::string command) {
else if (c == '$') {
// find the next one
for (long unsigned int j = i + 1; i < command.length(); ++j) {
if (command[j] == '$') {
if (command[j] == '$' && command[j - 1] != '\\') {
// found!
auto toSend = command.substr(i + 1);
toSend = toSend.substr(0, toSend.find_first_of('$'));
result += parseDollar(toSend);
auto toSend = command.substr(i + 1, j - (i + 1));
std::string toSendWithRemovedEscapes = "";
for (std::size_t k = 0; k < toSend.length(); ++k) {
if (toSend[k] == '\\' && (k + 1) < toSend.length()) {
char next = toSend[k + 1];
if (next == '$' || next == '{' || next == '}') {
continue;
}
}
toSendWithRemovedEscapes += toSend[k];
}
result += parseDollar(toSendWithRemovedEscapes);
i = j;
break;
}
if (j + 1 == command.length()) {
Debug::log(ERR, "Unescaped $ in a module, module command: ");
Debug::log(ERR, "Unpaired $ in a module, module command: ");
Debug::log(NONE, command);
}
}

View File

@ -285,7 +285,9 @@ void parseLine(std::string& line) {
return;
}
if (line.find("}") != std::string::npos && ConfigManager::currentCategory != "") {
std::size_t closingBrace = line.find("}");
if (closingBrace != std::string::npos && ConfigManager::currentCategory != "" &&
(closingBrace == 0 || line[closingBrace - 1] != '\\')) {
ConfigManager::currentCategory = "";
return;
}