From d8b99b1dff5ccfca092fea93789464603fd0a62e Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 21 Feb 2022 19:05:29 +0100 Subject: [PATCH] Escaped some characters needed to get emulator wildcards to work with certain directories. --- es-core/src/utils/FileSystemUtil.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/es-core/src/utils/FileSystemUtil.cpp b/es-core/src/utils/FileSystemUtil.cpp index 55281b859..471abeec2 100644 --- a/es-core/src/utils/FileSystemUtil.cpp +++ b/es-core/src/utils/FileSystemUtil.cpp @@ -142,10 +142,17 @@ namespace Utils if (dirContent.size() == 0) return files; + // Some characters need to be escaped in order for the regular expression to work. + std::string escPattern {Utils::String::replace(pattern, "*", ".*")}; + escPattern = Utils::String::replace(escPattern, ")", "\\)"); + escPattern = Utils::String::replace(escPattern, "(", "\\("); + escPattern = Utils::String::replace(escPattern, "]", "\\]"); + escPattern = Utils::String::replace(escPattern, "[", "\\["); + std::regex expression; try { - expression = Utils::String::replace(pattern, "*", ".*"); + expression = escPattern; } catch (...) { LOG(LogError) << "FileSystemUtil::getMatchingFiles(): Invalid regular expression " @@ -153,9 +160,9 @@ namespace Utils return files; } - for (auto& dir : dirContent) { - if (std::regex_match(dir, expression)) - files.emplace_back(dir); + for (auto& entry : dirContent) { + if (std::regex_match(entry, expression)) + files.emplace_back(entry); } return files;