From 9ba09e26d7fc667355d48a7d26361be6fb20612d Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 14 Apr 2020 09:36:04 +0200 Subject: QSettings: Read past UTF-8 BOM even without textcodec support Try to read past an UTF-8 BOM even if no textcodec support is available, but do set the status to FormatError then. This is in line with the general 'best effort' approach in QSettings. It also allows qmake (that is built without textcodec support) to gracefully load qt.conf files with a UTF-8 BOM, though non-Latin1 characters might still be misrepresented. Fixes: QTBUG-83456 Change-Id: I31b45dc5a8adf7950910897a2b33ae16990d3818 Reviewed-by: Thiago Macieira Reviewed-by: Joerg Bornemann --- src/corelib/io/qsettings.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index b191397e7e..c69ec908ed 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -1673,14 +1673,16 @@ bool QConfFileSettingsPrivate::readIniFile(const QByteArray &data, int sectionPosition = 0; bool ok = true; -#if QT_CONFIG(textcodec) // detect utf8 BOM const uchar *dd = (const uchar *)data.constData(); if (data.size() >= 3 && dd[0] == 0xef && dd[1] == 0xbb && dd[2] == 0xbf) { +#if QT_CONFIG(textcodec) iniCodec = QTextCodec::codecForName("UTF-8"); +#else + ok = false; +#endif dataPos = 3; } -#endif while (readIniLine(data, dataPos, lineStart, lineLen, equalsPos)) { char ch = data.at(lineStart); -- cgit v1.2.3