summaryrefslogtreecommitdiffstats
path: root/src/corelib/time
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2019-12-02 12:55:31 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2019-12-06 14:46:48 +0100
commit653c1aab185fe59a523f16ffe0cf7b9173c2ff68 (patch)
tree8b440d68bfd87c2860903a04ad9a51dc3dd994ab /src/corelib/time
parent187f4428239ace0a0c5b55d582729434d6e7ec82 (diff)
Fix handling of trailing space at the end of an ISO date-time
If milliseconds were followed by a space, the space was included in the count of "digits" read as the fractional part; since we read (up to) four digits (so that we round correctly if extras are given), a harmless apce could cause scaling down by too large a power of ten. Since QString::toInt() ignores leading space, we were also allowing interior space at the start of the milliseconds, which we should not, so catch that at the same time. Added tests, including one for the rounding that's the reason for reading the extra digit, when present. Fixes: QTBUG-80445 Change-Id: I606b29a94818a101f45c8b59a0f5d1f78893d78f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/time')
-rw-r--r--src/corelib/time/qdatetime.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp
index 8de4f7caf8..84b8a63c48 100644
--- a/src/corelib/time/qdatetime.cpp
+++ b/src/corelib/time/qdatetime.cpp
@@ -2375,7 +2375,12 @@ static QTime fromIsoTimeString(const QStringRef &string, Qt::DateFormat format,
if (!ok)
return QTime();
if (size > 8 && (string.at(8) == QLatin1Char(',') || string.at(8) == QLatin1Char('.'))) {
- const QStringRef msecStr(string.mid(9, 4));
+ QStringRef msecStr(string.mid(9, 4));
+ // toInt() ignores leading spaces, so catch them before calling it
+ if (!msecStr.isEmpty() && !msecStr.at(0).isDigit())
+ return QTime();
+ // We do, however, want to ignore *trailing* spaces.
+ msecStr = msecStr.trimmed();
int msecInt = msecStr.isEmpty() ? 0 : msecStr.toInt(&ok);
if (!ok)
return QTime();