QTimeZone: Fix isValidId()

Fix isValidId() which was failing valid IDs because it was splitting
name parts by \ instead of /.  it was also rejecting offset from UTC
formats names.  Add unit tests.

Task-number: QTBUG-35025
Change-Id: I4d23d2e54f4a9fac9afcc4eff0a02d6f4af21385
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
John Layt 2013-11-22 15:03:14 +01:00 committed by The Qt Project
parent b9c8073230
commit 689152e7c1
2 changed files with 35 additions and 2 deletions

View File

@ -453,9 +453,9 @@ bool QTimeZonePrivate::isValidId(const QByteArray &olsenId)
// Aliases such as "Etc/GMT+7" and "SystemV/EST5EDT" are valid so we need to accept digits
if (olsenId.contains(' '))
return false;
QList<QByteArray> parts = olsenId.split('\\');
QList<QByteArray> parts = olsenId.split('/');
foreach (const QByteArray &part, parts) {
if (part.size() > 14)
if (part.size() > 14 || part.size() < 1)
return false;
if (part.at(0) == '-')
return false;
@ -466,6 +466,8 @@ bool QTimeZonePrivate::isValidId(const QByteArray &olsenId)
&& !(ch == '_')
&& !(ch >= '0' && ch <= '9')
&& !(ch == '-')
&& !(ch == '+')
&& !(ch == ':')
&& !(ch == '.'))
return false;
}

View File

@ -56,6 +56,7 @@ private slots:
void createTest();
void nullTest();
void dataStreamTest();
void isTimeZoneIdAvailable();
void availableTimeZoneIds();
void stressTest();
void windowsId();
@ -347,6 +348,36 @@ void tst_QTimeZone::dataStreamTest()
QCOMPARE(tz2.id(), tz1.id());
}
void tst_QTimeZone::isTimeZoneIdAvailable()
{
QList<QByteArray> available = QTimeZone::availableTimeZoneIds();
foreach (const QByteArray &id, available)
QVERIFY(QTimeZone::isTimeZoneIdAvailable(id));
// a-z, A-Z, 0-9, '.', '-', '_' are valid chars
// Can't start with '-'
// Parts separated by '/', each part min 1 and max of 14 chars
QCOMPARE(QTimeZonePrivate::isValidId("az"), true);
QCOMPARE(QTimeZonePrivate::isValidId("AZ"), true);
QCOMPARE(QTimeZonePrivate::isValidId("09"), true);
QCOMPARE(QTimeZonePrivate::isValidId("a/z"), true);
QCOMPARE(QTimeZonePrivate::isValidId("a.z"), true);
QCOMPARE(QTimeZonePrivate::isValidId("a-z"), true);
QCOMPARE(QTimeZonePrivate::isValidId("a_z"), true);
QCOMPARE(QTimeZonePrivate::isValidId(".z"), true);
QCOMPARE(QTimeZonePrivate::isValidId("_z"), true);
QCOMPARE(QTimeZonePrivate::isValidId("12345678901234"), true);
QCOMPARE(QTimeZonePrivate::isValidId("12345678901234/12345678901234"), true);
QCOMPARE(QTimeZonePrivate::isValidId("a z"), false);
QCOMPARE(QTimeZonePrivate::isValidId("a\\z"), false);
QCOMPARE(QTimeZonePrivate::isValidId("a,z"), false);
QCOMPARE(QTimeZonePrivate::isValidId("/z"), false);
QCOMPARE(QTimeZonePrivate::isValidId("-z"), false);
QCOMPARE(QTimeZonePrivate::isValidId("123456789012345"), false);
QCOMPARE(QTimeZonePrivate::isValidId("123456789012345/12345678901234"), false);
QCOMPARE(QTimeZonePrivate::isValidId("12345678901234/123456789012345"), false);
}
void tst_QTimeZone::availableTimeZoneIds()
{
if (debug) {