Skip to content

feat: add safe preview and controlled save for files containing NUL bytes#487

Closed
wyu71 wants to merge 1 commit into
linuxdeepin:masterfrom
wyu71:feat/invalid-char-preview
Closed

feat: add safe preview and controlled save for files containing NUL bytes#487
wyu71 wants to merge 1 commit into
linuxdeepin:masterfrom
wyu71:feat/invalid-char-preview

Conversation

@wyu71

@wyu71 wyu71 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

概述

为 deepin-editor 实现"含无效字符 NUL 文件的安全预览与受控保存"功能。

当文件包含 \x00 NUL 字节时,编辑器进入只读预览模式,将 NUL 显示为可见文本 \00,并通过明确确认流程控制编辑和保存,避免用户误覆盖原文件造成不可逆损坏。

主要改动

模块 改动
FileLoadThread 在原始字节层面检测 NUL,转义为 \00
EditWrapper 预览态字段、只读切换、Edit Anyway、保存成功后退出预览
WarningNotices 新增 "Edit Anyway" 按钮与信号
Window 统一 confirmInvalidCharSave 三按钮确认弹窗(Don't Save / Save As / Save Anyway),Ctrl+S 与关闭 Tab 共用同一入口;预览模式拒绝同路径 Save As;备份短路
CSyntaxHighlighter \00 高亮(红色背景 + 白色文字)
翻译文件 新增 en / zh_CN / zh_HK / zh_TW 文案

验收标准

  • US-1 打开含 NUL 文件:显示 hello\00world,默认只读,警告条 + Edit Anyway,\00 高亮,原文件不变
  • US-2 Edit Anyway:可编辑,警告条关闭,仍处预览模式
  • US-3 Ctrl+S:三按钮确认框,Don't Save / Save As / Save Anyway 各路径正确
  • US-4 关闭 Tab:复用同一弹窗,取消不关闭
  • US-5 Save As 保护:拒绝同路径,新路径成功,原文件保留 NUL
  • US-6 会话恢复:预览态修改不保存退出后,重新检测原文件进入只读预览,不恢复未保存编辑稿
  • US-7 普通 Save As 回归:无异常 *

测试

已通过人工功能验证(US-1 至 US-7)及 AI 代码审查。

关联

…ytes

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

Task: https://pms.uniontech.com/task-view-392417.html
Multica Issue: https://agent-dev.uniontech.com/issues/14dc6e9a-d392-4a6a-b8a9-f295ea204c96

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @wyu71, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: wyu71

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@dengzhongyuan365-dev

Copy link
Copy Markdown
Member

Superseded by #489 (created under the correct GitHub account dengzhongyuan365-dev). Closing this PR as it was created under the wrong account (wyu71).

@wyu71

wyu71 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #489 (created under the correct GitHub account dengzhongyuan365-dev). This PR was created under the wrong account (wyu71) and should be closed.

@wyu71

wyu71 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #489. Created under wrong account, closing.

@wyu71 wyu71 closed this Jul 22, 2026
@wyu71
wyu71 deleted the feat/invalid-char-preview branch July 22, 2026 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants