From 1158e57f400de8f0e9ec0b8b21bfcf0d5dfc830f Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Tue, 13 Oct 2015 23:33:26 +0200 Subject: Correctly read octal escapes from Clonk-config --- src/Util.cpp | 14 ++++++++++++++ src/Util.hpp | 1 + src/crsm.cpp | 4 ++-- 3 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Util.cpp b/src/Util.cpp index 014f1f8..0a0b6a5 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -1,5 +1,7 @@ #include "Util.hpp" +#include + namespace Util { QString trimQuotes(QString string, bool& trimmed) { @@ -132,4 +134,16 @@ namespace Util { return ret; } + QString& unescapeClonkString(QString&& string) + { + static QRegularExpression escapeExp(R"(\\[0-7]+)"); + QRegularExpressionMatch match; + while((match = escapeExp.match(string)).hasMatch()) + { + unsigned char c = (unsigned char)match.capturedRef(0).mid(1).toInt(0, 8); + + string.replace(match.capturedStart(), match.capturedLength(), c); + } + return string; + } } diff --git a/src/Util.hpp b/src/Util.hpp index c2ed916..8f5ff86 100644 --- a/src/Util.hpp +++ b/src/Util.hpp @@ -13,4 +13,5 @@ namespace Util { QString escape(const QString& string, const QChar escapeChar = '\\', const QString& escapeChars = ""); QString joinEscape(const QStringList& list, const QChar joinChar, const QChar escapeChar = '\\'); QStringList splitEscaped(const QString& joined, const QChar splitChar, const QChar escapeChar = '\\'); + QString& unescapeClonkString(QString&& string); } diff --git a/src/crsm.cpp b/src/crsm.cpp index fbdeea1..3fe1000 100644 --- a/src/crsm.cpp +++ b/src/crsm.cpp @@ -1642,12 +1642,12 @@ void CRSM::applyConfig() if(!Config.Auto.Volatile.Clonk.ServerNick.isEmpty() && !Config.Auto.Volatile.Clonk.ServerPCName.isEmpty()) break; if(nickExp.exactMatch(line.trimmed())) { - Config.Auto.Volatile.Clonk.ServerNick = nickExp.cap(1); + Config.Auto.Volatile.Clonk.ServerNick = Util::unescapeClonkString(nickExp.cap(1)); continue; } else if(pcNameExp.exactMatch(line.trimmed())) { - Config.Auto.Volatile.Clonk.ServerPCName = pcNameExp.cap(1); + Config.Auto.Volatile.Clonk.ServerPCName = Util::unescapeClonkString(pcNameExp.cap(1)); continue; } } -- cgit v1.2.3-54-g00ecf