Logging: Accept .ini files written by QSettings
For keys, QSettings escapes all characters outside of [-a-zA-Z0-9_.] by using percent encoding, and changes '/' to '\'. That is, settings.setValue("qt.*", true) will be written to an .ini file as qt.%2A=true This means that QSettings can not be used to write general-purpose qtlogging.ini files. Fix this by applying the reverse transformation method from QSettings when reading in the .ini file. [ChangeLog][Logging] Qt will now accept qtlogging.ini files written by QSettings. Task-number: QTBUG-69548 Change-Id: I55b7a8b433291268dc6855901f72b1c04f8ee6d3 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
01d2f35b69
commit
bd0279c417
@ -99,6 +99,7 @@
|
||||
#define QT_FEATURE_process -1
|
||||
#define QT_FEATURE_regularexpression -1
|
||||
#define QT_FEATURE_renameat2 -1
|
||||
#define QT_FEATURE_settings -1
|
||||
#define QT_FEATURE_sharedmemory -1
|
||||
#define QT_FEATURE_slog2 -1
|
||||
#define QT_FEATURE_statx -1
|
||||
|
@ -46,6 +46,11 @@
|
||||
#include <QtCore/qdir.h>
|
||||
#include <QtCore/qcoreapplication.h>
|
||||
|
||||
#if QT_CONFIG(settings)
|
||||
#include <QtCore/qsettings.h>
|
||||
#include <QtCore/private/qsettings_p.h>
|
||||
#endif
|
||||
|
||||
// We can't use the default macros because this would lead to recursion.
|
||||
// Instead let's define our own one that unconditionally logs...
|
||||
#define debugMsg QMessageLogger(__FILE__, __LINE__, __FUNCTION__, "qt.core.logging").debug
|
||||
@ -230,7 +235,14 @@ void QLoggingSettingsParser::parseNextLine(QStringRef line)
|
||||
int equalPos = line.indexOf(QLatin1Char('='));
|
||||
if (equalPos != -1) {
|
||||
if (line.lastIndexOf(QLatin1Char('=')) == equalPos) {
|
||||
const auto pattern = line.left(equalPos).trimmed();
|
||||
const auto key = line.left(equalPos).trimmed();
|
||||
#if QT_CONFIG(settings)
|
||||
QString tmp;
|
||||
QSettingsPrivate::iniUnescapedKey(key.toUtf8(), 0, key.length(), tmp);
|
||||
QStringRef pattern = QStringRef(&tmp, 0, tmp.length());
|
||||
#else
|
||||
QStringRef pattern = key;
|
||||
#endif
|
||||
const auto valueStr = line.mid(equalPos + 1).trimmed();
|
||||
int value = -1;
|
||||
if (valueStr == QLatin1String("true"))
|
||||
|
@ -187,6 +187,13 @@ private slots:
|
||||
"default=false");
|
||||
QCOMPARE(parser.rules().size(), 1);
|
||||
|
||||
// QSettings escapes * to %2A when writing.
|
||||
parser.setContent("[Rules]\n"
|
||||
"module.%2A=false");
|
||||
QCOMPARE(parser.rules().size(), 1);
|
||||
QCOMPARE(parser.rules().first().category, QString("module."));
|
||||
QCOMPARE(parser.rules().first().flags, QLoggingRule::LeftFilter);
|
||||
|
||||
parser.setContent("[OtherSection]\n"
|
||||
"default=false");
|
||||
QCOMPARE(parser.rules().size(), 0);
|
||||
|
Loading…
Reference in New Issue
Block a user