summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2019-12-02 16:15:14 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2019-12-10 17:26:02 +0100
commitbf65c277892f6f322fa689c06d81ba9b1d9a8038 (patch)
tree671358b6334f4f946657c9f465405db3fb46d576 /tests/auto/corelib
parentc5777ad81cf395dfebbe46c629caca2b933d8008 (diff)
Fix more mis-handling of spaces in ISO date format strings
ISO date format doesn't allow spaces within a date, although 3339 does allow a space to replace the T between date and time. Sixteen tests added to check this all failed. So clean up the handling of spaces in the parsing of ISO date-time strings. [ChangeLog][QtCore][QDateTime] ISO 8601: parsing of dates now requires a punctuator as separator (it previously allowed any non-digit; officially only a dash should be allowed) and parsing of date-times no longer tolerates spaces in the numeric fields: an internal space is only allowed in an ISO 8601 date-time as replacement for the T between date and time. Change-Id: I24d110e71d416ecef74e196d5ee270b59d1bd813 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
index 7778542736..c03d112560 100644
--- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
@@ -2213,8 +2213,46 @@ void tst_QDateTime::fromStringDateFormat_data()
QTest::newRow("trailing space") // QTBUG-80445
<< QString("2000-01-02 03:04:05.678 ")
<< Qt::ISODate << QDateTime(QDate(2000, 1, 2), QTime(3, 4, 5, 678));
+
+ // Invalid spaces (but keeping field widths correct):
QTest::newRow("space before millis")
<< QString("2000-01-02 03:04:05. 678") << Qt::ISODate << QDateTime();
+ QTest::newRow("space after seconds")
+ << QString("2000-01-02 03:04:5 .678") << Qt::ISODate << QDateTime();
+ QTest::newRow("space before seconds")
+ << QString("2000-01-02 03:04: 5.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("space after minutes")
+ << QString("2000-01-02 03:4 :05.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("space before minutes")
+ << QString("2000-01-02 03: 4:05.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("space after hour")
+ << QString("2000-01-02 3 :04:05.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("space before hour")
+ << QString("2000-01-02 3:04:05.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("space after day")
+ << QString("2000-01-2 03:04:05.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("space before day")
+ << QString("2000-01- 2 03:04:05.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("space after month")
+ << QString("2000-1 -02 03:04:05.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("space before month")
+ << QString("2000- 1-02 03:04:05.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("space after year")
+ << QString("200 -01-02 03:04:05.678") << Qt::ISODate << QDateTime();
+
+ // Spaces as separators:
+ QTest::newRow("sec-milli space")
+ << QString("2000-01-02 03:04:05 678") << Qt::ISODate
+ // Should be invalid, but we ignore trailing cruft (in some cases)
+ << QDateTime(QDate(2000, 1, 2), QTime(3, 4, 5));
+ QTest::newRow("min-sec space")
+ << QString("2000-01-02 03:04 05.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("hour-min space")
+ << QString("2000-01-02 03 04:05.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("mon-day space")
+ << QString("2000-01 02 03:04:05.678") << Qt::ISODate << QDateTime();
+ QTest::newRow("year-mon space")
+ << QString("2000 01-02 03:04:05.678") << Qt::ISODate << QDateTime();
// Normal usage:
QTest::newRow("ISO +01:00") << QString::fromLatin1("1987-02-13T13:24:51+01:00")