summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/tools/qdatetime.cpp5
-rw-r--r--tests/auto/corelib/tools/qdate/tst_qdate.cpp7
2 files changed, 12 insertions, 0 deletions
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp
index 1ab5665893..5438f00c67 100644
--- a/src/corelib/tools/qdatetime.cpp
+++ b/src/corelib/tools/qdatetime.cpp
@@ -1281,6 +1281,11 @@ QDate QDate::fromString(const QString& string, Qt::DateFormat format)
}
#endif // QT_NO_TEXTDATE
case Qt::ISODate: {
+ // Semi-strict parsing, must be long enough and have non-numeric separators
+ if (string.size() < 10 || string.at(4).isDigit() || string.at(7).isDigit()
+ || (string.size() > 10 && string.at(10).isDigit())) {
+ return QDate();
+ }
const int year = string.mid(0, 4).toInt();
if (year <= 0 || year > 9999)
return QDate();
diff --git a/tests/auto/corelib/tools/qdate/tst_qdate.cpp b/tests/auto/corelib/tools/qdate/tst_qdate.cpp
index b91de092e8..807dcf5cbe 100644
--- a/tests/auto/corelib/tools/qdate/tst_qdate.cpp
+++ b/tests/auto/corelib/tools/qdate/tst_qdate.cpp
@@ -944,6 +944,13 @@ void tst_QDate::fromStringDateFormat_data()
QTest::newRow("iso2") << QDate(1999, 11, 14).toString(Qt::ISODate) << Qt::ISODate << QDate(1999, 11, 14);
QTest::newRow("iso3") << QString("0999-01-01") << Qt::ISODate << QDate(999, 1, 1);
QTest::newRow("iso3b") << QString("0999-01-01") << Qt::ISODate << QDate(999, 1, 1);
+ QTest::newRow("iso4") << QString("2000101101") << Qt::ISODate << QDate();
+ QTest::newRow("iso5") << QString("2000/01/01") << Qt::ISODate << QDate(2000, 1, 1);
+ QTest::newRow("iso6") << QString("2000-01-01 blah") << Qt::ISODate << QDate(2000, 1, 1);
+ QTest::newRow("iso7") << QString("2000-01-011blah") << Qt::ISODate << QDate();
+ QTest::newRow("iso8") << QString("2000-01-01blah") << Qt::ISODate << QDate(2000, 1, 1);
+ QTest::newRow("iso9") << QString("-001-01-01") << Qt::ISODate << QDate();
+ QTest::newRow("iso10") << QString("99999-01-01") << Qt::ISODate << QDate();
// Test Qt::RFC2822Date format (RFC 2822).
QTest::newRow("RFC 2822") << QString::fromLatin1("13 Feb 1987 13:24:51 +0100")