diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2012-05-19 21:59:49 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-23 12:00:44 +0200 |
commit | f2b8a1237fb5f27957ab3dc7c84335c1dea90ce7 (patch) | |
tree | a6915fbf452c78c5987813f228e08560af901acb /tests/auto/qregexp | |
parent | 3484489af72c0cad3fac28f7c8b953c32e6feb9a (diff) | |
download | qt4-tools-f2b8a1237fb5f27957ab3dc7c84335c1dea90ce7.tar.gz |
QRegExp: fix crash
Fixes a crash when invoking various QRegExp methods on an object
*before* doing any match. For instance fixes:
QRegExp re;
re.matchedLength(); // crash
Backport of commit 136c2bf18446f2bbe7052d638c29edbc0b8ef6bc from qtbase.
Task-number: QTBUG-23352
Change-Id: I9c239ff790a139c7820ef1aeced89d31320ae6b0
Reviewed-by: Andy Shaw <andy.shaw@digia.com>
Reviewed-by: Janne Anttila <janne.anttila@digia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/qregexp')
-rw-r--r-- | tests/auto/qregexp/tst_qregexp.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/qregexp/tst_qregexp.cpp b/tests/auto/qregexp/tst_qregexp.cpp index 051eb8e0f3..a8d817e3b8 100644 --- a/tests/auto/qregexp/tst_qregexp.cpp +++ b/tests/auto/qregexp/tst_qregexp.cpp @@ -107,6 +107,8 @@ private slots: void QTBUG_7049_data(); void QTBUG_7049(); void interval(); + void validityCheck_data(); + void validityCheck(); }; // Testing get/set functions @@ -1452,6 +1454,32 @@ void tst_QRegExp::interval() } } +void tst_QRegExp::validityCheck_data() +{ + QTest::addColumn<QString>("pattern"); + QTest::addColumn<bool>("validity"); + QTest::newRow("validity01") << QString() << true; + QTest::newRow("validity02") << QString("abc.*abc") << true; + QTest::newRow("validity03") << QString("[a-z") << false; + QTest::newRow("validity04") << QString("a(b") << false; +} + +void tst_QRegExp::validityCheck() +{ + QFETCH(QString, pattern); + + QRegExp rx(pattern); + QTEST(rx.isValid(), "validity"); + QCOMPARE(rx.matchedLength(), -1); + QCOMPARE(rx.pos(), -1); + QCOMPARE(rx.cap(), QString("")); + + QRegExp rx2(rx); + QTEST(rx2.isValid(), "validity"); + QCOMPARE(rx2.matchedLength(), -1); + QCOMPARE(rx2.pos(), -1); + QCOMPARE(rx2.cap(), QString("")); +} QTEST_APPLESS_MAIN(tst_QRegExp) #include "tst_qregexp.moc" |