summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenji Sugita <sugita@sra.co.jp>2010-03-22 14:38:10 (GMT)
committerBenjamin Poulain <benjamin.poulain@nokia.com>2010-03-22 14:51:37 (GMT)
commit77b913e5f8fa93c62a245685d55d76eec2e9021a (patch)
treea7674c32ec5ee5ad9be545190acc193c37d1eaa0
parent9da453e5579ebb6fb0361e4df4cfa7107e560b23 (diff)
downloadQt-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.cpp2
-rw-r--r--tests/auto/qstringlist/tst_qstringlist.cpp10
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"