feat: add safe preview and controlled save for files containing NUL bytes#489
Conversation
There was a problem hiding this comment.
Sorry @dengzhongyuan365-dev, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
07dded7 to
4a93eb5
Compare
…ng NUL bytes When a file contains \x00 NUL bytes, the editor now enters a read-only preview mode that displays NUL as visible text \00 with red highlight, shows a warning bar with an "Edit Anyway" button, and enforces a three-button confirmation dialog (Don't Save / Save As / Save Anyway) for both Ctrl+S and close-tab flows. Save As to the original path is rejected in preview mode. Auto-backup is short-circuited during preview to prevent persisting unsaved preview edits across sessions. Key changes: - FileLoadThread: detect NUL bytes at raw byte level, escape to \00 - EditWrapper: preview state fields, read-only toggle, Edit Anyway, exit-preview on successful save - WarningNotices: add "Edit Anyway" button and signal - Window: unified confirmInvalidCharSave dialog, Save As same-path rejection, backup short-circuit for preview mode - CSyntaxHighlighter: \00 highlight (red background, white text) - Translations: new messages for en, zh_CN, zh_HK, zh_TW PMS: ztgd2026062500034
4a93eb5 to
b032397
Compare
deepin pr auto review★ 总体评分:92分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // src/common/fileloadthread.cpp
// 优化 NUL 字符检测与转义的性能,减少一次全量遍历
bool hasNul = false;
int nulIndex = indata.indexOf('\x00');
if (nulIndex != -1) {
hasNul = true;
qDebug() << "NUL bytes detected in file, escaping to \\00";
indata.replace('\x00', "\\00");
} |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dengzhongyuan365-dev, lzwind 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) |
…ytes Cherry-pick of PR linuxdeepin#489 (merge commit b5df59d) from master to release/eagle. Conflicts resolved preferring release/eagle base while preserving all NUL safety preview functionality. When a file contains \x00 NUL bytes, the editor enters a read-only preview mode that displays NUL as visible text \00 with red highlight, shows a warning bar with an "Edit Anyway" button, and enforces a three-button confirmation dialog (Don't Save / Save As / Save Anyway) for both Ctrl+S and close-tab flows. Save As to the original path is rejected in preview mode. Auto-backup is short-circuited during preview to prevent persisting unsaved preview edits across sessions. PMS: bug-371363 Multica Issue: https://agent-dev.uniontech.com/issues/14dc6e9a-d392-4a6a-b8a9-f295ea204c96
…ytes Cherry-pick of PR linuxdeepin#489 (merge commit b5df59d) from master to release/eagle. Conflicts resolved preferring release/eagle base while preserving all NUL safety preview functionality. When a file contains \x00 NUL bytes, the editor enters a read-only preview mode that displays NUL as visible text \00 with red highlight, shows a warning bar with an "Edit Anyway" button, and enforces a three-button confirmation dialog (Don't Save / Save As / Save Anyway) for both Ctrl+S and close-tab flows. Save As to the original path is rejected in preview mode. Auto-backup is short-circuited during preview to prevent persisting unsaved preview edits across sessions. PMS: bug-371363 Multica Issue: https://agent-dev.uniontech.com/issues/14dc6e9a-d392-4a6a-b8a9-f295ea204c96
…ytes Cherry-pick of PR linuxdeepin#489 (merge commit b5df59d) from master to release/eagle. Conflicts resolved preferring release/eagle base while preserving all NUL safety preview functionality. When a file contains \x00 NUL bytes, the editor enters a read-only preview mode that displays NUL as visible text \00 with red highlight, shows a warning bar with an "Edit Anyway" button, and enforces a three-button confirmation dialog (Don't Save / Save As / Save Anyway) for both Ctrl+S and close-tab flows. Save As to the original path is rejected in preview mode. Auto-backup is short-circuited during preview to prevent persisting unsaved preview edits across sessions. PMS: bug-371363 Multica Issue: https://agent-dev.uniontech.com/issues/14dc6e9a-d392-4a6a-b8a9-f295ea204c96
…ytes Cherry-pick of PR #489 (merge commit b5df59d) from master to release/eagle. Conflicts resolved preferring release/eagle base while preserving all NUL safety preview functionality. When a file contains \x00 NUL bytes, the editor enters a read-only preview mode that displays NUL as visible text \00 with red highlight, shows a warning bar with an "Edit Anyway" button, and enforces a three-button confirmation dialog (Don't Save / Save As / Save Anyway) for both Ctrl+S and close-tab flows. Save As to the original path is rejected in preview mode. Auto-backup is short-circuited during preview to prevent persisting unsaved preview edits across sessions. PMS: bug-371363 Multica Issue: https://agent-dev.uniontech.com/issues/14dc6e9a-d392-4a6a-b8a9-f295ea204c96
概述
为 deepin-editor 实现"含无效字符 NUL 文件的安全预览与受控保存"功能。
当文件包含
\x00NUL 字节时,编辑器进入只读预览模式,将 NUL 显示为可见文本\00,并通过明确确认流程控制编辑和保存,避免用户误覆盖原文件造成不可逆损坏。主要改动
FileLoadThread\00EditWrapperWarningNoticesWindowconfirmInvalidCharSave三按钮确认弹窗(Don't Save / Save As / Save Anyway),Ctrl+S 与关闭 Tab 共用同一入口;预览模式拒绝同路径 Save As;备份短路CSyntaxHighlighter\00高亮(红色背景 + 白色文字)验收标准
hello\00world,默认只读,警告条 + Edit Anyway,\00高亮,原文件不变*测试
已通过人工功能验证(US-1 至 US-7)及 AI 代码审查。