Commit 96ae49ef authored by Volker Krause's avatar Volker Krause
Browse files

Be more tolerant to how GBFS file names are specified

There's at least one provider adding the ".json" suffix in the discovery
response, so let's handle that as well. Gives us GBFS coverage e.g. in
Brussels.
parent 85c2fd26
......@@ -4,6 +4,7 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include <../src/lib/gbfs/gbfs.cpp>
#include <gbfs/gbfsservice.h>
#include <QObject>
......@@ -23,6 +24,14 @@ private Q_SLOTS:
QStandardPaths::setTestModeEnabled(true);
}
void testFileType()
{
QCOMPARE(GBFS::typeForKeyName(u"system_information"), GBFS::SystemInformation);
QCOMPARE(GBFS::typeForKeyName(u"geofencing_zones"), GBFS::GeofencingZones);
QCOMPARE(GBFS::typeForKeyName(u"geofencing_zones.json"), GBFS::GeofencingZones);
QCOMPARE(GBFS::typeForKeyName(u"geofencing_zones_information"), GBFS::Unknown);
}
void testServiceRepo()
{
const auto &services = GBFSServiceRepository::services();
......
......@@ -42,7 +42,7 @@ GBFS::FileType GBFS::typeForKeyName(QStringView v)
{
const auto s = v.toUtf8();
for (auto it = std::begin(file_info_map); it != std::end(file_info_map); ++it) {
if (std::strcmp((*it).fileName, s.constData()) == 0) {
if (std::strcmp((*it).fileName, s.constData()) == 0 || (s.endsWith(".json") && std::strncmp((*it).fileName, s.constData(), s.size() - 5) == 0)) {
return static_cast<GBFS::FileType>(std::distance(std::begin(file_info_map), it));
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment