Commit b1726331 authored by Volker Krause's avatar Volker Krause
Browse files

Check IATA BCBP input a bit more strictly

Fixes garbage extraction from certain Jira emails.

BUG: 407895
parent a73bb5a0
......@@ -90,12 +90,16 @@ private Q_SLOTS:
QTest::newRow("too short") << QStringLiteral("M1DESMARAIS/LUC ");
QTest::newRow("wrong leg count") << QStringLiteral("M2DESMARAIS/LUC EABC123 YULFRAAC 0834 326J001A0025 100");
QTest::newRow("too short repeated mandatory section") << QStringLiteral("M1DOE/JOHN EXXX007 TXLBRUSN 2592 11");
QTest::newRow("bug 407895") << QStringLiteral("M2Mobi Lab / ML-586 [In Progress]\nSplit Fooo.Config from main Fooo\n\n========================================================");
}
void testParserInvalid()
{
QFETCH(QString, message);
const auto res = IataBcbpParser::parse(message);
if (!res.isEmpty()) {
qDebug().noquote() << QJsonDocument(JsonLdDocument::toJson(res)).toJson();
}
QVERIFY(res.isEmpty());
}
};
......
......@@ -50,6 +50,11 @@ static int readHexValue(const QStringRef &s, int width)
return s.mid(0, width).toInt(nullptr, 16);
}
static bool isValidAirportCode(const QString &s)
{
return std::all_of(s.begin(), s.end(), [](const QChar c) { return c.isLetter() && c.isUpper(); });
}
static int parseRepeatedMandatorySection(const QStringRef& msg, FlightReservation& res)
{
if (msg.size() < 24) { // pre-checking data, technically incomplete, but we can make use of this nevertheless
......@@ -64,6 +69,10 @@ static int parseRepeatedMandatorySection(const QStringRef& msg, FlightReservatio
flight.setDepartureAirport(airport);
airport.setIataCode(msg.mid(10, 3).toString());
flight.setArrivalAirport(airport);
if (!isValidAirportCode(flight.departureAirport().iataCode()) || !isValidAirportCode(flight.arrivalAirport().iataCode())) {
qCWarning(Log) << "IATA airport code format violation";
return -1;
}
Airline airline;
airline.setIataCode(msg.mid(13, 3).trimmed().toString());
......
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