From e31febb024782406243179e7ec24e535daf5e6a9 Mon Sep 17 00:00:00 2001 From: JiDe Zhang Date: Thu, 16 Aug 2018 17:18:22 +0800 Subject: QSysInfo(linux): Use UTF-8 format read file ...Of the "readEtcFile" function According to https://www.freedesktop.org/software/systemd/man/os-release.html it says "All strings should be in UTF-8 format". Change-Id: Icd2d75eca2ac7273c7f587a1e3c0430cc6d2c31d Reviewed-by: Thiago Macieira --- src/corelib/global/qglobal.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/corelib/global/qglobal.cpp') diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index a369bbe490..6c608dab74 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -2142,11 +2142,20 @@ struct QUnixOSVersion static QString unquote(const char *begin, const char *end) { + // man os-release says: + // Variable assignment values must be enclosed in double + // or single quotes if they include spaces, semicolons or + // other special characters outside of A–Z, a–z, 0–9. Shell + // special characters ("$", quotes, backslash, backtick) + // must be escaped with backslashes, following shell style. + // All strings should be in UTF-8 format, and non-printable + // characters should not be used. It is not supported to + // concatenate multiple individually quoted strings. if (*begin == '"') { Q_ASSERT(end[-1] == '"'); - return QString::fromLatin1(begin + 1, end - begin - 2); + return QString::fromUtf8(begin + 1, end - begin - 2); } - return QString::fromLatin1(begin, end - begin); + return QString::fromUtf8(begin, end - begin); } static QByteArray getEtcFileContent(const char *filename) { -- cgit v1.2.3