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,9 +73,16 @@ std::optional<SvgCursorMetaData> SvgCursorMetaData::parse(const QString &filePat
return std::nullopt;
}
QList<SvgCursorMetaDataEntry> entries;
if (document.isArray()) {
if (!document.isArray()) {
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()) {
@ -87,9 +94,6 @@ std::optional<SvgCursorMetaData> SvgCursorMetaData::parse(const QString &filePat
return std::nullopt;
}
}
} else {
return std::nullopt;
}
return SvgCursorMetaData{
.entries = entries,