Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/elfmz/far2l.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelfmz <fenix1905@tut.by>2022-10-30 23:37:24 +0300
committerelfmz <fenix1905@tut.by>2022-10-30 23:37:24 +0300
commit59efd1d81e2359e9c2406236d240f2451609ca1b (patch)
tree74cec133edf33aa7fd8e25d9012beb2fc420c378
parentf0dc969e1d9006c5120ccbd6d26c9b80bc60e077 (diff)
unescape strings parsed from mtab file (touch #1381)
-rw-r--r--far2l/src/mix/MountInfo.cpp3
-rw-r--r--utils/include/Environment.h2
-rw-r--r--utils/src/Environment.cpp22
3 files changed, 22 insertions, 5 deletions
diff --git a/far2l/src/mix/MountInfo.cpp b/far2l/src/mix/MountInfo.cpp
index b04a730d..f33b0cea 100644
--- a/far2l/src/mix/MountInfo.cpp
+++ b/far2l/src/mix/MountInfo.cpp
@@ -218,6 +218,9 @@ MountInfo::MountInfo(bool for_location_menu)
while (std::getline(is, line)) {
parts.clear();
StrExplode(parts, line, " \t");
+ for (auto &part : parts) {
+ Environment::UnescapeCLikeSequences(part);
+ }
if (parts.size() > 1 && StrStartsFrom(parts[1], "/")
&& (!for_location_menu || !lme.Match(parts[1].c_str()))) {
bool multi_thread_friendly;
diff --git a/utils/include/Environment.h b/utils/include/Environment.h
index 242010fd..fa9f9fd2 100644
--- a/utils/include/Environment.h
+++ b/utils/include/Environment.h
@@ -3,6 +3,8 @@
#include <vector>
namespace Environment
{
+ void UnescapeCLikeSequences(std::string &s);
+
// similar to getenv but provides extra resolution of 'special' variables that may miss in normal envs
const char *GetVariable(const char *name);
diff --git a/utils/src/Environment.cpp b/utils/src/Environment.cpp
index b08c5031..3faaa61f 100644
--- a/utils/src/Environment.cpp
+++ b/utils/src/Environment.cpp
@@ -120,21 +120,21 @@ static void UnescapeCLikeSequence(std::string &s, size_t &i)
// \x## where ## is a hexadecimal char code
case 'x': if (i + 1 < s.size()) {
unsigned long code = strtol(s.substr(i, 2).c_str(), nullptr, 16);
- i++;
+ i+= 2;
ReplaceSubstringAt(s, i - 4, i, StrPrintf("%c", (char)(unsigned char)code));
} break;
// \u#### where #### is a hexadecimal UTF16 code
case 'u': if (i + 3 < s.size()) {
unsigned long code = strtol(s.substr(i, 4).c_str(), nullptr, 16);
- i+= 3;
+ i+= 4;
ReplaceSubstringAt(s, i - 6, i, StrPrintf("%lc", (wchar_t)code));
} break;
- // \u######## where ######## is a hexadecimal UTF32 code
+ // \U######## where ######## is a hexadecimal UTF32 code
case 'U': if (i + 7 < s.size()) {
unsigned long code = strtol(s.substr(i, 8).c_str(), nullptr, 16);
- i+= 7;
+ i+= 8;
ReplaceSubstringAt(s, i - 10, i, StrPrintf("%lc", (wchar_t)code));
} break;
@@ -142,13 +142,25 @@ static void UnescapeCLikeSequence(std::string &s, size_t &i)
case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7':
if (i + 1 < s.size()) {
unsigned long code = strtol(s.substr(i - 1, 3).c_str(), nullptr, 8);
- i++;
+ i+= 2;
ReplaceSubstringAt(s, i - 4, i, StrPrintf("%c", (char)(unsigned char)code));
} break;
}
--i; // adjust i back
}
+void UnescapeCLikeSequences(std::string &s)
+{
+ if (s.size() > 1) {
+ for (size_t i = s.size() - 1; i > 0; --i) {
+ if (s[i - 1] == '\\') {
+ size_t j = i;
+ UnescapeCLikeSequence(s, j);
+ }
+ }
+ }
+}
+
// nasty and allmighty function that actually implements ExpandString and ParseCommandLine
static bool ExpandStringOrParseCommandLine(std::string &s, Arguments *args, bool empty_if_missing, bool allow_exec_cmd)
{