summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2020-02-14 17:59:33 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2020-02-27 10:48:25 +0100
commit0ad4f86729d3ab1ee7eafc0dace44ef1fdb11e55 (patch)
tree9175bbeaa30289a7539a9b7d2123d4b160ccaade /tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
parentaf837734b2259201f126b206bd5299497e080f7b (diff)
Purge QRegExp use in QDateTime's rfcDateImpl()
Replace with a parser which actually does the job right, fixing various infelicities in the parsing in the process. Make the parser strict about formatting. Adjusted tests to match. Fixed some QTime invalidity tests to each test only one invalidity at a time (the invalid year and day tests also used an invalid month). [ChangeLog][QtCore][QDateTime] The parser for the Qt::RFC2822Date format is now stricter, requiring the text to exactly match the form of one of the relevant formats. A valid date or time will still be parsed, even if the other part of the content is invalid, as long as it (and any offset, if present) has the right form. In particular, the parser now rejects texts with trailing cruft (other than space). Fixes: QTBUG-80038 Change-Id: Id25675afd75f82f6351f20e79f0154f3ceda35ac Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp')
-rw-r--r--tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp13
1 files changed, 5 insertions, 8 deletions
diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
index 26ad91271d..a6a68b66ed 100644
--- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
@@ -2397,11 +2397,8 @@ void tst_QDateTime::fromStringDateFormat_data()
<< Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC);
QTest::newRow("RFC 2822 with day +0000") << QString::fromLatin1("Thu, 01 Jan 1970 00:12:34 +0000")
<< Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC);
- // Should be invalid, but current implementation would just ignore the
- // offset as trailing junk if we insist on the space:
QTest::newRow("RFC 2822 missing space before +0100")
- << QString::fromLatin1("Thu, 01 Jan 1970 00:12:34+0100") << Qt::RFC2822Date
- << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::OffsetFromUTC, 3600);
+ << QString::fromLatin1("Thu, 01 Jan 1970 00:12:34+0100") << Qt::RFC2822Date << QDateTime();
// No timezone assume UTC
QTest::newRow("RFC 2822 no timezone") << QString::fromLatin1("01 Jan 1970 00:12:34")
<< Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC);
@@ -2417,10 +2414,10 @@ void tst_QDateTime::fromStringDateFormat_data()
<< Qt::RFC2822Date << invalidDateTime();
QTest::newRow("RFC 2822 invalid year") << QString::fromLatin1("13 Fev 0000 13:24:51 +0100")
<< Qt::RFC2822Date << invalidDateTime();
- // Test invalid characters (currently ignoring trailing junk, but see QTBUG-80038).
+ // Test invalid characters.
QTest::newRow("RFC 2822 invalid character at end")
<< QString::fromLatin1("01 Jan 2012 08:00:00 +0100!")
- << Qt::RFC2822Date << QDateTime(QDate(2012, 1, 1), QTime(7, 0, 0, 0), Qt::UTC);
+ << Qt::RFC2822Date << QDateTime();
QTest::newRow("RFC 2822 invalid character at front")
<< QString::fromLatin1("!01 Jan 2012 08:00:00 +0100")
<< Qt::RFC2822Date << invalidDateTime();
@@ -2458,10 +2455,10 @@ void tst_QDateTime::fromStringDateFormat_data()
QTest::newRow("RFC 850 and 1036 date only")
<< QString::fromLatin1("Fri Nov 01 2002")
<< Qt::RFC2822Date << invalidDateTime();
- // Test invalid characters (currently ignoring trailing junk, but see QTBUG-80038).
+ // Test invalid characters.
QTest::newRow("RFC 850 and 1036 invalid character at end")
<< QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100!")
- << Qt::RFC2822Date << QDateTime(QDate(2012, 1, 1), QTime(7, 0, 0, 0), Qt::UTC);
+ << Qt::RFC2822Date << QDateTime();
QTest::newRow("RFC 850 and 1036 invalid character at front")
<< QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100")
<< Qt::RFC2822Date << invalidDateTime();