From c2ece0be06e79fd3b4eda2f1a0d4b68b4a03d363 Mon Sep 17 00:00:00 2001 From: Maxim Mikhaylov Date: Sun, 22 May 2022 02:34:54 +0300 Subject: [PATCH] Added escaping of `{`, `}` and `$` --- src/bar/BarCommands.cpp | 19 ++++++++++++++----- src/config/ConfigManager.cpp | 4 +++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/bar/BarCommands.cpp b/src/bar/BarCommands.cpp index 8b09b6a..7c53aec 100644 --- a/src/bar/BarCommands.cpp +++ b/src/bar/BarCommands.cpp @@ -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); } } diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 1dfa0b0..b574b34 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -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; }