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

Return empty value for non-existing UIC 918.3 blocks

This prevents JS extractor scripts from accidentally accessing an invalid
block object.
parent 3faccbdd
......@@ -67,21 +67,20 @@ QVariant Uic9183Parser::block(const QString &name) const
return {};
}
if (name == QLatin1String(Uic9183Head::RecordId)) {
return QVariant::fromValue(findBlock<Uic9183Head>());
}
if (name == QLatin1String(Uic9183TicketLayout::RecordId)) {
return QVariant::fromValue(ticketLayout());
}
if (name == QLatin1String(Fcb::UicRailTicketData::RecordId)) {
return QVariant::fromValue(findBlock<Fcb::UicRailTicketData>());
}
if (name == QLatin1String(Vendor0080BLBlock::RecordId)) {
return QVariant::fromValue(findBlock<Vendor0080BLBlock>());
}
if (name == QLatin1String(Vendor0080VUBlock::RecordId)) {
return QVariant::fromValue(findBlock<Vendor0080VUBlock>());
#define BLOCK_FROM_NAME(Type) \
if (name == QLatin1String(Type::RecordId)) { \
const auto block = findBlock<Type>(); \
return block.isValid() ? QVariant::fromValue(block) : QVariant(); \
}
BLOCK_FROM_NAME(Uic9183Head)
BLOCK_FROM_NAME(Uic9183TicketLayout)
BLOCK_FROM_NAME(Fcb::UicRailTicketData)
BLOCK_FROM_NAME(Vendor0080BLBlock)
BLOCK_FROM_NAME(Vendor0080VUBlock)
#undef BLOCK_FROM_NAME
return QVariant::fromValue(findBlock(name.toUtf8().constData()));
}
......
......@@ -233,7 +233,7 @@ Vendor0080BLSubBlock Vendor0080BLBlock::findSubBlock(const char id[3]) const
QVariant Vendor0080BLBlock::findSubBlock(const QString &str) const
{
if (str.size() != 3) {
if (str.size() != 3 || !isValid()) {
return {};
}
const auto b = findSubBlock(str.toUtf8().constData());
......
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