Fastfetch: unescape strings only when parsing .conf files

So that `NO_CONFIG=1 ./fastfetch --os-key \\\\ -s os -l none` prints `\\: *`
This commit is contained in:
李通洲
2023-08-15 16:39:20 +08:00
parent 2b2ebe0823
commit 8835f66b8c
5 changed files with 47 additions and 37 deletions
+37 -1
View File
@@ -584,6 +584,7 @@ static bool parseConfigFile(FFdata* data, const char* path)
char* line = NULL;
size_t len = 0;
ssize_t read;
FF_STRBUF_AUTO_DESTROY unescaped = ffStrbufCreate();
while ((read = getline(&line, &len, file)) != -1)
{
@@ -628,7 +629,42 @@ static bool parseConfigFile(FFdata* data, const char* path)
--lineEnd;
}
parseOption(data, lineStart, valueStart);
if (strchr(valueStart, '\\'))
{
// Unescape all `\x`s
const char* value = valueStart;
while(*value != '\0')
{
if(*value != '\\')
{
ffStrbufAppendC(&unescaped, *value);
++value;
continue;
}
++value;
switch(*value)
{
case 'n': ffStrbufAppendC(&unescaped, '\n'); break;
case 't': ffStrbufAppendC(&unescaped, '\t'); break;
case 'e': ffStrbufAppendC(&unescaped, '\e'); break;
case '\\': ffStrbufAppendC(&unescaped, '\\'); break;
default:
ffStrbufAppendC(&unescaped, '\\');
ffStrbufAppendC(&unescaped, *value);
break;
}
++value;
}
parseOption(data, lineStart, unescaped.chars);
ffStrbufClear(&unescaped);
}
else
{
parseOption(data, lineStart, valueStart);
}
}
if(line != NULL)