From f9557afcaf8e7d6ef3a2cd4fae06da6f05c7b17c Mon Sep 17 00:00:00 2001 From: zhanghongyuan Date: Wed, 30 Sep 2026 16:07:56 +0800 Subject: [PATCH] fix: parse encodes.ini by structure instead of fixed offsets getSupportEncoding() assumed an 8-char 'encodes=' prefix with mid(8, length-2) and split entries without trimming, so a renamed key, trailing spaces or CRLF line endings silently produced invalid encoding names (the root cause pattern of issue 57271). Parse the '[group]' and 'key=value' lines structurally, trim entries and drop empty ones. Log: Influence: encoding list loading --- src/common/utils.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/common/utils.cpp b/src/common/utils.cpp index 3dbca0f8..44131cf2 100644 --- a/src/common/utils.cpp +++ b/src/common/utils.cpp @@ -1208,12 +1208,29 @@ QVector> Utils::getSupportEncoding() qDebug() << "readStream.readLine()"; QString group = readStream.readLine(); qDebug() << "group:" << group; - QString key = group.mid(1, group.length() - 2); + if (!group.startsWith('[') || !group.endsWith(']')) { + qWarning() << "unexpected group line, skipped:" << group; + continue; + } + QString key = group.mid(1, group.length() - 2).trimmed(); QString encodes = readStream.readLine(); qDebug() << "encodes:" << encodes; - QString value = encodes.mid(8, encodes.length() - 2); + int eqIdx = encodes.indexOf('='); + if (eqIdx == -1) { + qWarning() << "unexpected encodes line, skipped:" << encodes; + continue; + } + QString value = encodes.mid(eqIdx + 1).trimmed(); + QStringList encodeNames; + const QStringList parts = value.split(',', Qt::SkipEmptyParts); + for (const QString &part : parts) { + const QString name = part.trimmed(); + if (!name.isEmpty()) { + encodeNames.append(name); + } + } qDebug() << "value:" << value; - tmpEncodeVec.append(QPair(key, value.split(","))); + tmpEncodeVec.append(QPair(key, encodeNames)); } qDebug() << "tmpEncodeVec:" << tmpEncodeVec; s_groupEncodeVec = tmpEncodeVec;