From 2350c7e35c7b21ab86e54e43d1e1bfddb1746922 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 25 Feb 2014 15:16:17 +0100 Subject: Make parsing of categories in logging rules more strict Do not accept rules with wildcards in the middle. Change-Id: If6fa71629c46bc4127aa8bd475643bc0e8a9f57c Reviewed-by: Thiago Macieira --- src/corelib/io/qloggingregistry.cpp | 18 +++++++++--------- .../io/qloggingregistry/tst_qloggingregistry.cpp | 8 ++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/corelib/io/qloggingregistry.cpp b/src/corelib/io/qloggingregistry.cpp index 20eb2e13f5..ab29c42325 100644 --- a/src/corelib/io/qloggingregistry.cpp +++ b/src/corelib/io/qloggingregistry.cpp @@ -134,20 +134,20 @@ void QLoggingRule::parse(const QString &pattern) messageType = QtCriticalMsg; } - int index = category.indexOf(QLatin1Char('*')); - if (index < 0) { + flags = Invalid; + if (!category.contains(QLatin1Char('*'))) { flags = FullText; } else { - flags = Invalid; - if (index == 0) { - flags |= RightFilter; - category.remove(0, 1); - index = category.indexOf(QLatin1Char('*')); - } - if (index == (category.length() - 1)) { + if (category.endsWith(QLatin1Char('*'))) { flags |= LeftFilter; category.chop(1); } + if (category.startsWith(QLatin1Char('*'))) { + flags |= RightFilter; + category.remove(0, 1); + } + if (category.contains(QLatin1Char('*'))) // '*' only supported at start/end + flags = Invalid; } } diff --git a/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp b/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp index 56545bb909..5796b2f221 100644 --- a/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp +++ b/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp @@ -152,6 +152,14 @@ private slots: << QString("*qt.*.debug") << QString("qt.io") << QtDebugMsg << Match; QTest::newRow("_star_.qt._star_.warning-qt.io") << QString("*.qt.*.warning") << QString("qt.io") << QtDebugMsg << NoMatch; + QTest::newRow("**") + << QString("**") << QString("qt.core.io") << QtDebugMsg << Match; + + // * outside of start/end + QTest::newRow("qt.*.io") + << QString("qt.*.io") << QString("qt.core.io") << QtDebugMsg << Invalid; + QTest::newRow("***") + << QString("***") << QString("qt.core.io") << QtDebugMsg << Invalid; } void QLoggingRule_parse() -- cgit v1.2.3