summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qregexp
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2019-05-27 19:00:09 +0200
committerMarc Mutz <marc.mutz@kdab.com>2019-05-27 17:33:30 +0000
commitb9f96cacc99c8a242f45f4581843a6b1c67501f4 (patch)
tree2a2a96a3bd34fd4900beb6cfa17c788cc2187114 /tests/auto/corelib/tools/qregexp
parentc04bd30de072793faee5166cff866a4c4e0a9dd7 (diff)
QRegExp: remove an out of bounds access into QString
... spotted with the brand-new checks for that in QCharRef. The rx[i] == ~~~ check is clearly wrong, as rx is the regexp we're building and `i` was not supposed to index into it. The intended meaning was wc[i] == ~~~, testing if we were seeing the closing bracket of a character set. We need to check for that immediately for dealing with the special syntax of []...] where the ] belongs to the character set (it can't be the closing one as character sets cannot be empty). Fix and add a regression test. Bonus: this code was almost unchanged since 2009. Change-Id: I958cd87fc25558e9d202d18b3dd4a35d0db16d8d Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'tests/auto/corelib/tools/qregexp')
-rw-r--r--tests/auto/corelib/tools/qregexp/tst_qregexp.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp b/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp
index a98d37d733..a8111af6c1 100644
--- a/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp
+++ b/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp
@@ -834,6 +834,13 @@ void tst_QRegExp::testEscapingWildcard_data(){
QTest::newRow("a true '\\' in input") << "\\Qt;" << "\\Qt;" << true;
QTest::newRow("two true '\\' in input") << "\\\\Qt;" << "\\\\Qt;" << true;
QTest::newRow("a '\\' at the end") << "\\\\Qt;\\" << "\\\\Qt;\\" << true;
+
+ QTest::newRow("[]\\] matches ]") << "[]\\]" << "]" << true;
+ QTest::newRow("[]\\] matches \\") << "[]\\]" << "\\" << true;
+ QTest::newRow("[]\\] does not match [") << "[]\\]" << "[" << false;
+ QTest::newRow("[]\\]a matches ]a") << "[]\\]a" << "]a" << true;
+ QTest::newRow("[]\\]a matches \\a") << "[]\\]a" << "\\a" << true;
+ QTest::newRow("[]\\]a does not match [a") << "[]\\]a" << "[a" << false;
}
void tst_QRegExp::testEscapingWildcard(){