summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2022-04-01 12:07:10 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2022-04-07 23:04:04 +0200
commit9fee35a2eda68b5968d911d5e14d298b91418d2c (patch)
tree418dae18a32e3a947c32d12dc75ed851857da82f /tests/auto
parentd82301a9002fc8bd1b2a81ae841cf087e8781739 (diff)
Fix assertion failure when parsing a doubly-invalid date-time text
When the date-time string falls in a spring-forward (so is invalid) and one of the fields of the parsed string doesn't match the format it's meant to (e.g. a single-digit seconds field when format ss was specified), a check that the current fall-back date-time is between the minimum and maximum for the parser object failed, triggering an assertion. In any case, an invalid default-value wasn't useful to the code that parsed a single section of the date-time string, so brute-force the current value to a valid date-time (when possible) using the usual round-trip via milliseconds since the epoch. Added the test-case which first revealed the problem, plus a couple more informed by it, to exercise the same code-paths with fewer things failing. Fixes: QTBUG-102199 Pick-to: 6.3 6.2 5.15 Change-Id: I658308614505ef25f4c97d0de6148acb54a65a0f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/text/qlocale/tst_qlocale.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
index 01395a566c..23346ed54c 100644
--- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
+++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
@@ -1967,7 +1967,8 @@ void tst_QLocale::toDateTime_data()
QTest::addColumn<QDateTime>("result");
QTest::addColumn<QString>("format");
QTest::addColumn<QString>("string");
- QTest::addColumn<bool>("clean"); // No non-format letters in format string
+ // No non-format letters in format string, no time-zone (t format):
+ QTest::addColumn<bool>("clean");
QTest::newRow("1C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(5, 14, 0))
<< "d/M/yyyy hh:h:mm" << "1/12/1974 05:5:14" << true;
@@ -2021,6 +2022,18 @@ void tst_QLocale::toDateTime_data()
QTest::newRow("12no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(15, 0, 0))
<< "d'd'dd/M/yyh" << "1d01/12/7415" << false;
+ QTest::newRow("short-ss") // QTBUG-102199: trips over an assert in CET
+ << "C" << QDateTime() // Single-digit seconds does not match ss format.
+ << u"ddd, d MMM yyyy HH:mm:ss"_qs << u"Sun, 29 Mar 2020 02:26:3"_qs << true;
+
+ QTest::newRow("short-ss-Z") // Same, but with a valid date-time:
+ << "C" << QDateTime()
+ << u"ddd, d MMM yyyy HH:mm:ss t"_qs << u"Sun, 29 Mar 2020 02:26:3 Z"_qs << false;
+
+ QTest::newRow("s-Z") // Same, but with a format that accepts the single digit:
+ << "C" << QDateTime(QDate(2020, 3, 29), QTime(2, 26, 3), Qt::UTC)
+ << u"ddd, d MMM yyyy HH:mm:s t"_qs << u"Sun, 29 Mar 2020 02:26:3 Z"_qs << false;
+
QTest::newRow("RFC-1123")
<< "C" << QDateTime(QDate(2007, 11, 1), QTime(18, 8, 30))
<< "ddd, dd MMM yyyy hh:mm:ss 'GMT'" << "Thu, 01 Nov 2007 18:08:30 GMT" << false;