diff --git a/src/modules/locale/GeoIP.cpp b/src/modules/locale/GeoIP.cpp index f11a44db7..3001273bb 100644 --- a/src/modules/locale/GeoIP.cpp +++ b/src/modules/locale/GeoIP.cpp @@ -30,8 +30,11 @@ GeoIP::~GeoIP() } GeoIP::RegionZonePair -GeoIP::splitTZString( const QString& timezoneString ) +GeoIP::splitTZString( const QString& tz ) { + QString timezoneString( tz ); + timezoneString.remove( '\\' ); + QStringList tzParts = timezoneString.split( '/', QString::SkipEmptyParts ); if ( tzParts.size() >= 2 ) { diff --git a/src/modules/locale/GeoIPTests.cpp b/src/modules/locale/GeoIPTests.cpp index 554e6f0c0..5b5c27bff 100644 --- a/src/modules/locale/GeoIPTests.cpp +++ b/src/modules/locale/GeoIPTests.cpp @@ -165,3 +165,27 @@ GeoIPTests::testXMLbad() QCOMPARE( tz.first, QString() ); #endif } + +void GeoIPTests::testSplitTZ() +{ + auto tz = GeoIP::splitTZString( QLatin1String("Moon/Dark_side") ); + QCOMPARE( tz.first, QLatin1String("Moon") ); + QCOMPARE( tz.second, QLatin1String("Dark_side") ); + + // Some providers return weirdly escaped data + tz = GeoIP::splitTZString( QLatin1String("America\\/NewYork") ); + QCOMPARE( tz.first, QLatin1String("America") ); + QCOMPARE( tz.second, QLatin1String("NewYork") ); // That's not actually the zone name + + // Check that bogus data fails + tz = GeoIP::splitTZString( QString() ); + QCOMPARE( tz.first, QString() ); + + tz = GeoIP::splitTZString( QLatin1String("America.NewYork") ); + QCOMPARE( tz.first, QString() ); + + // Check that three-level is split properly + tz = GeoIP::splitTZString( QLatin1String("America/North Dakota/Beulah") ); + QCOMPARE( tz.first, QLatin1String("America") ); + QCOMPARE( tz.second, QLatin1String("North Dakota/Beulah") ); +} diff --git a/src/modules/locale/GeoIPTests.h b/src/modules/locale/GeoIPTests.h index 87918ace0..7aaefee81 100644 --- a/src/modules/locale/GeoIPTests.h +++ b/src/modules/locale/GeoIPTests.h @@ -37,6 +37,7 @@ private Q_SLOTS: void testXML2(); void testXMLalt(); void testXMLbad(); + void testSplitTZ(); }; #endif