utils: Validate svg cursor metadata better

Metadata array must contain at least one item.
This commit is contained in:
Vlad Zahorodnii 2024-08-22 16:48:15 +03:00
parent 5cff8cd2d1
commit e03fb08bcc

View file

@ -73,24 +73,28 @@ std::optional<SvgCursorMetaData> SvgCursorMetaData::parse(const QString &filePat
return std::nullopt; return std::nullopt;
} }
QList<SvgCursorMetaDataEntry> entries; if (!document.isArray()) {
if (document.isArray()) {
const QJsonArray array = document.array();
for (int i = 0; i < array.size(); ++i) {
const QJsonValue element = array.at(i);
if (!element.isObject()) {
return std::nullopt;
}
if (const auto entry = SvgCursorMetaDataEntry::parse(element.toObject())) {
entries.append(entry.value());
} else {
return std::nullopt;
}
}
} else {
return std::nullopt; return std::nullopt;
} }
const QJsonArray array = document.array();
if (array.isEmpty()) {
return std::nullopt;
}
QList<SvgCursorMetaDataEntry> entries;
for (int i = 0; i < array.size(); ++i) {
const QJsonValue element = array.at(i);
if (!element.isObject()) {
return std::nullopt;
}
if (const auto entry = SvgCursorMetaDataEntry::parse(element.toObject())) {
entries.append(entry.value());
} else {
return std::nullopt;
}
}
return SvgCursorMetaData{ return SvgCursorMetaData{
.entries = entries, .entries = entries,
}; };