Improve MANIFEST.MF parsing
Previously, we would only properly parse LF-encoded manifests, and even those only if they used the recommended casing. This commit allows the parser to recognise CR and CRLF newlines, and also makes the name comparison case insensitive to align with the specification. (Though not completely: we still don't support multiline values) Signed-off-by: Kationor <n96211028@gmail.com> (cherry picked from commit b40a1973bfe590fb21b486419a8d223b2c6aae7f)
This commit is contained in:
parent
d453240a94
commit
a914747416
@ -8,6 +8,7 @@
|
|||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonValue>
|
#include <QJsonValue>
|
||||||
|
#include <QRegularExpression>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
@ -15,6 +16,8 @@
|
|||||||
#include "minecraft/mod/ModDetails.h"
|
#include "minecraft/mod/ModDetails.h"
|
||||||
#include "settings/INIFile.h"
|
#include "settings/INIFile.h"
|
||||||
|
|
||||||
|
static QRegularExpression newlineRegex("\r\n|\n|\r");
|
||||||
|
|
||||||
namespace ModUtils {
|
namespace ModUtils {
|
||||||
|
|
||||||
// NEW format
|
// NEW format
|
||||||
@ -487,11 +490,11 @@ bool processZIP(Mod& mod, [[maybe_unused]] ProcessingLevel level)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// quick and dirty line-by-line parser
|
// quick and dirty line-by-line parser
|
||||||
auto manifestLines = file.readAll().split('\n');
|
auto manifestLines = QString(file.readAll()).split(newlineRegex);
|
||||||
QString manifestVersion = "";
|
QString manifestVersion = "";
|
||||||
for (auto& line : manifestLines) {
|
for (auto& line : manifestLines) {
|
||||||
if (QString(line).startsWith("Implementation-Version: ")) {
|
if (line.startsWith("Implementation-Version: ", Qt::CaseInsensitive)) {
|
||||||
manifestVersion = QString(line).remove("Implementation-Version: ");
|
manifestVersion = line.remove("Implementation-Version: ", Qt::CaseInsensitive);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user