fix: support opening JSON files detected as MIME subtype#463
Merged
Conversation
Files with $schema field are detected as application/schema+json instead of application/json, causing them to be rejected. 添加MIME类型继承检查,支持被系统识别为子类型的文件打开。 Log: 修复含$schema字段的JSON文件无法打开的问题 PMS: BUG-362033 Influence: 修复后所有JSON子类型(如schema+json)文件均可正常打开。
deepin pr auto review你好!我是CodeGeeX。我已经仔细审查了你提供的Git Diff,本次修改主要涉及 以下是我从语法逻辑、代码质量、代码性能和代码安全四个维度提出的详细审查意见和改进建议: 1. 语法与逻辑
2. 代码质量
3. 代码性能
4. 代码安全
改进后的代码建议以下是针对 // 1. 使用 QSet 提升查找性能,并移除危险的 application/octet-stream
static const QSet<QString> SupportedTextMimeTypes = {
"application/cmd",
"application/javascript",
"application/json",
"application/pkix-cert",
// "application/octet-stream", // 严重安全风险,建议移除!
"application/sql",
"application/vnd.apple.mpegurl",
"application/vnd.nokia.qt.qmakeprofile",
"application/vnd.nokia.xml.qt.resource",
"application/x-desktop",
"application/x-designer",
"application/x-empty",
"application/x-msdos-program",
"application/x-pearl",
"application/x-php",
"application/x-shellscript",
"application/x-sh",
"application/x-theme",
"application/x-cue",
"application/x-csh",
"application/x-asp",
"application/x-subrip",
"application/x-text",
"application/x-trash",
"application/x-xbel",
"application/x-yaml",
"application/x-pem-key",
"application/xml",
"application/yaml",
"application/x-zerosize",
"image/svg+xml",
"application/x-perl",
"application/x-ruby",
"application/x-mpegURL",
"application/x-wine-extension-ini",
"model/vrml",
"application/pkix-cert+pem",
"application/x-pak",
"application/x-code-workspace",
"application/toml",
"audio/x-mod",
"application/pkix-attr-cert",
"application/x-x509-ca-cert",
"text/plain" // 建议将 text/plain 加入集合,统一通过 inherits 处理
};
bool Utils::isMimeTypeSupport(const QString &filepath)
{
// 减少不必要的调试输出,或使用 QLoggingCategory
// qDebug() << "Checking MIME support for:" << filepath;
// 复用 QMimeDatabase 对象,利用其内部缓存
static QMimeDatabase mimeDatabase;
QMimeType mime = mimeDatabase.mimeTypeForFile(filepath, QMimeDatabase::MatchMode::MatchContent);
if (!mime.isValid()) {
return false;
}
QString mimeType = mime.name();
// 1. 快速路径:直接匹配或者是 text/ 前缀
if (SupportedTextMimeTypes.contains(mimeType) || mimeType.startsWith("text/")) {
return true;
}
// 2. 兼容 .pub 后缀(修正大小写和点号)
if (filepath.endsWith(".pub", Qt::CaseInsensitive)) {
return true;
}
// 3. 检查继承关系 (包含了对 text/plain 及其他文本类型的继承)
for (const QString &supported : SupportedTextMimeTypes) {
if (mime.inherits(supported)) {
return true;
}
}
return false;
}关于被删除的 |
lzwind
approved these changes
May 20, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, wyu71 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Files with $schema field are detected as application/schema+json instead of application/json, causing them to be rejected.
添加MIME类型继承检查,支持被系统识别为子类型的文件打开。
Log: 修复含$schema字段的JSON文件无法打开的问题
PMS: BUG-362033
Influence: 修复后所有JSON子类型(如schema+json)文件均可正常打开。