Tolerate spaces at start and end of a POSIX zone descriptor

It's easy to do and makes an unremarkable user error harmless.
In the process, add a comment to make QTBUG-112006 visible in the code.

Pick-to: 6.9 6.8 6.5
Fixes: QTBUG-135109
Change-Id: I6b9cb431bf5b005fc0f9cdbb5cf30c90fa1154c4
Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
This commit is contained in:
Edward Welbourne 2025-03-25 10:14:55 +01:00
parent cdcaaaeee3
commit f682406162
2 changed files with 8 additions and 3 deletions

View File

@ -514,7 +514,7 @@ static inline bool asciiIsLetter(char ch)
namespace {
struct PosixZone
struct PosixZone // TODO: QTBUG-112006 - make this cross-platform.
{
enum {
InvalidOffset = INT_MIN,
@ -600,7 +600,7 @@ static auto validatePosixRule(const QByteArray &posixRule, bool requireOffset =
// See also calculatePosixTransition()'s reference.
const auto parts = posixRule.split(',');
const struct { bool isValid, hasDst; } fail{false, false}, good{true, parts.size() > 1};
const QByteArray &zoneinfo = parts.at(0);
const QByteArray &zoneinfo = parts.at(0).trimmed();
if (zoneinfo.isEmpty())
return fail;
@ -656,7 +656,7 @@ static QList<QTimeZonePrivate::Data> calculatePosixTransitions(const QByteArray
PosixZone stdZone, dstZone;
{
const QByteArray &zoneinfo = parts.at(0);
const QByteArray &zoneinfo = parts.at(0).trimmed();
const char *begin = zoneinfo.constBegin();
stdZone = PosixZone::parse(begin, zoneinfo.constEnd());

View File

@ -1468,6 +1468,11 @@ void tst_QTimeZone::tzTest()
QVERIFY(tzposix.isValid());
QVERIFY(tzposix.hasDaylightTime());
// Cope with stray space at start of value (QTBUG-135109):
QTimeZone syd(" AEST-10AEDT,M10.1.0,M4.1.0/3");
QVERIFY(syd.isValid());
QVERIFY(syd.hasDaylightTime());
// RHEL has been seen with this as Africa/Casablanca's POSIX rule:
QTzTimeZonePrivate permaDst("<+00>0<+01>,0/0,J365/25");
const QTimeZone utcP1("UTC+01:00"); // Should always have same offset as permaDst