diff options
author | Marc Mutz <marc.mutz@qt.io> | 2021-11-29 11:24:49 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-11-30 00:50:50 +0000 |
commit | 7933012c67c8dc0a9044828fa724331d727c358b (patch) | |
tree | 9d667ae4ea5c8ad5832264be7ab15a7b3b369d5d /tests | |
parent | f452222af98cc93adb786c146ca99087c18dca1d (diff) |
Check that QStringView::split() w/rvalue QRegularExpression returns valid data
This test currently passes in Qt 6, but fails in Qt 5.15, thus the
QT_VERSION check.
Task-number: QTBUG-98653
Change-Id: I3c7b9bc7ef74f605ff63768b38c473296274d0de
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit 8568a6386c1691e296e288021d7fd6316695cfbb)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp index 48d4de0aa4..14f9c10219 100644 --- a/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp +++ b/tests/auto/corelib/text/qregularexpression/tst_qregularexpression.cpp @@ -83,6 +83,7 @@ private slots: void threadSafety_data(); void threadSafety(); + void returnsViewsIntoOriginalString(); void wildcard_data(); void wildcard(); void testInvalidWildcard_data(); @@ -2338,6 +2339,34 @@ void tst_QRegularExpression::threadSafety() } } +void tst_QRegularExpression::returnsViewsIntoOriginalString() +{ + // https://bugreports.qt.io/browse/QTBUG-98653 + + auto to_void = [](const auto *p) -> const void* { return p; }; + + // GIVEN + // a QString with dynamically-allocated data: + const QString string = QLatin1String("A\nA\nB\nB\n\nC\nC"); // NOT QStringLiteral! + const auto stringDataAddress = to_void(string.data()); + + // and a view over said QString: + QStringView view(string); + const auto viewDataAddress = to_void(view.data()); + QCOMPARE(stringDataAddress, viewDataAddress); + + // WHEN + // we call view.split() with a temporary QRegularExpression object + const auto split = view.split(QRegularExpression( "(\r\n|\n|\r)" ), Qt::KeepEmptyParts); + + // THEN + // the returned views should point into the underlying string: +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + QEXPECT_FAIL("", "QTBUG-98653", Continue); +#endif + QCOMPARE(to_void(split.front().data()), stringDataAddress); +} + void tst_QRegularExpression::wildcard_data() { QTest::addColumn<QString>("pattern"); |