fix: give error when components have bad uids

This allows other code to reject proceeding when the UID is bad, which
is generally a good idea. :p

Co-authored-by: Sefa Eyeoglu <contact@scrumplex.net>
Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow 2023-01-31 15:01:25 -03:00
parent 435273e08a
commit 4166d9ab7b
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469

View File

@ -39,6 +39,8 @@
#include "minecraft/ParseUtils.h"
#include <minecraft/MojangVersionFormat.h>
#include <QRegularExpression>
using namespace Json;
static void readString(const QJsonObject &root, const QString &key, QString &variable)
@ -121,6 +123,15 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc
out->uid = root.value("fileId").toString();
}
const QRegularExpression valid_uid_regex{ QRegularExpression::anchoredPattern(QStringLiteral(R"(\w+(?:\.\w+)*)")) };
if (!valid_uid_regex.match(out->uid).hasMatch()) {
qCritical() << "The component's 'uid' contains illegal characters! UID:" << out->uid;
out->addProblem(
ProblemSeverity::Error,
QObject::tr("The component's 'uid' contains illegal characters! This can cause security issues.")
);
}
out->version = root.value("version").toString();
MojangVersionFormat::readVersionProperties(root, out.get());