diff options
author | Kenji Sugita <sugita@sra.co.jp> | 2010-03-22 14:38:10 (GMT) |
---|---|---|
committer | Benjamin Poulain <benjamin.poulain@nokia.com> | 2010-03-22 14:51:37 (GMT) |
commit | 77b913e5f8fa93c62a245685d55d76eec2e9021a (patch) | |
tree | a7674c32ec5ee5ad9be545190acc193c37d1eaa0 | |
parent | 9da453e5579ebb6fb0361e4df4cfa7107e560b23 (diff) | |
download | Qt-77b913e5f8fa93c62a245685d55d76eec2e9021a.zip Qt-77b913e5f8fa93c62a245685d55d76eec2e9021a.tar.gz Qt-77b913e5f8fa93c62a245685d55d76eec2e9021a.tar.bz2 |
Fix behavior change QStringList::join() for null
Before 4.6.2 both str.isNull() and str.isEmpty() return true for the
following code.
QStringList list;
QString str = list.join(QString());
This commit revert the behavior change introduced by
7461ed5227e3002c4a6f74d458aa0255b7c1217d. Joining null
QString was giving a empty string instead of a null
string.
Reviewed-by: Benjamin Poulain <benjamin.poulain@nokia.com>
-rw-r--r-- | src/corelib/tools/qstringlist.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qstringlist/tst_qstringlist.cpp | 10 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/corelib/tools/qstringlist.cpp b/src/corelib/tools/qstringlist.cpp index e9bdf57..32a0b1e 100644 --- a/src/corelib/tools/qstringlist.cpp +++ b/src/corelib/tools/qstringlist.cpp @@ -414,6 +414,8 @@ QString QtPrivate::QStringList_join(const QStringList *that, const QString &sep) totalLength += sep.size() * (size - 1); QString res; + if (totalLength == 0) + return res; res.reserve(totalLength); for (int i = 0; i < that->size(); ++i) { if (i) diff --git a/tests/auto/qstringlist/tst_qstringlist.cpp b/tests/auto/qstringlist/tst_qstringlist.cpp index 8429303..fb28bf4 100644 --- a/tests/auto/qstringlist/tst_qstringlist.cpp +++ b/tests/auto/qstringlist/tst_qstringlist.cpp @@ -77,6 +77,7 @@ private slots: void streamingOperator(); void join() const; void join_data() const; + void join_emptiness() const; }; extern const char email[]; @@ -311,5 +312,14 @@ void tst_QStringList::join_data() const << QString("a b c"); } +void tst_QStringList::join_emptiness() const +{ + QStringList list; + QString string = list.join(QString()); + + QCOMPARE(string.isEmpty(), true); + QCOMPARE(string.isNull(), true); +} + QTEST_APPLESS_MAIN(tst_QStringList) #include "tst_qstringlist.moc" |