fix(editor): check parent MIME types to support subtype files in isMimeTypeSupport#465
Conversation
There was a problem hiding this comment.
Sorry @Resurgamz, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
6ffef3a to
34bee3d
Compare
deepin pr auto review你好!我是CodeGeeX。我已仔细审查了你提供的Git Diff。本次修改主要是将局部变量提取为静态常量、优化了QMimeDatabase的调用方式,并增加了基于MIME类型继承关系的检查。 以下是针对语法逻辑、代码质量、代码性能和代码安全四个方面的详细审查意见和改进建议: 一、 语法与逻辑
二、 代码质量
三、 代码性能
四、 代码安全
💡 综合改进后的代码建议// 使用 QSet 提升查询性能,并按字母排序便于维护
static const QSet<QString> SupportedTextMimeTypes = {
"application/cmd",
"application/javascript",
"application/json",
"application/pkix-cert",
// "application/octet-stream", // 安全建议:移除此项,避免误判二进制文件
"application/sql",
"application/toml",
"application/vnd.apple.mpegurl",
"application/vnd.nokia.qt.qmakeprofile",
"application/vnd.nokia.xml.qt.resource",
"application/x-asp",
"application/x-code-workspace",
"application/x-csh",
"application/x-cue",
"application/x-desktop",
"application/x-designer",
"application/x-empty",
"application/x-mpegURL",
"application/x-msdos-program",
"application/x-pak",
"application/x-pem-key",
"application/x-perl", // 注意:确认 x-pearl 是否为拼写错误,已修正为 x-perl
"application/x-php",
"application/x-ruby",
"application/x-sh",
"application/x-shellscript",
"application/x-subrip",
"application/x-text",
"application/x-theme",
"application/x-trash",
"application/x-wine-extension-ini",
"application/x-xbel",
"application/x-yaml",
"application/x-zerosize",
"application/xml",
"application/yaml",
"audio/x-mod",
"image/svg+xml",
"model/vrml"
};
bool Utils::isMimeTypeSupport(const QString &filepath)
{
const QMimeType mime = QMimeDatabase().mimeTypeForFile(filepath, QMimeDatabase::MatchMode::MatchContent);
const QString mimeType = mime.name();
if (mimeType.startsWith("text/")) {
return true;
}
// 优化后缀检查:忽略大小写并精确匹配后缀
if (QFileInfo(filepath).suffix().compare("pub", Qt::CaseInsensitive) == 0) {
return true;
}
if (SupportedTextMimeTypes.contains(mimeType)) {
return true;
}
// 逻辑优化:仅在 MIME 有效且不在排除列表中时检查继承关系
// 注意:需排除 octet-stream 这种过于宽泛的基类,避免二进制文件被误判
if (mime.isValid()) {
for (const QString &supportedType : SupportedTextMimeTypes) {
// 可选:增加对宽泛类型的过滤条件
// if (supportedType == "application/octet-stream") continue;
if (mime.inherits(supportedType)) {
return true;
}
}
}
return false;
} |
…meTypeSupport - Retain QMimeType object to enable parent type lookup - Add parentMimeTypes() fallback to match subtypes against whitelist 修复(editor): 在 isMimeTypeSupport 中检查父 MIME 类型以支持子类型文件打开 Log: 通过父 MIME 类型继承关系扩展白名单匹配范围,修复子类型文件无法打开的问题 Bug: https://pms.uniontech.com/bug-view-362023.html
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, Resurgamz 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 |
|
/merge |
|
This pr cannot be merged! (status: unstable) |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
748ac61
into
linuxdeepin:release/eagle
fix(editor): check parent MIME types to support subtype files in isMimeTypeSupport
修复(editor): 在 isMimeTypeSupport 中检查父 MIME 类型以支持子类型文件打开
Log: 通过父 MIME 类型继承关系扩展白名单匹配范围,修复子类型文件无法打开的问题
Bug: https://pms.uniontech.com/bug-view-362023.html