Repository navigation
feat: detect text files by content instead of an extension allowlist - #25
Merged
Merged
Conversation
2 tasks done
1lck
approved these changes
Aug 9, 2026
puppyben1
pushed a commit
to puppyben1/Lithe-IDEA
that referenced
this pull request
Oct 14, 2026
chore(plugins): 将 dev.lithe.plugin.php-support 1.0.0 加入官方插件索引 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
18 of 21 tasks
xiaoyumuxi
added a commit
that referenced
this pull request
Nov 13, 2026
…hared/fixtures 副本 (#1853) (#1861) - 桌面测试改用 contractfixture.CoreFixture 读取所链接 Core 检出的 rust/fixtures, desktop-go.sh 导出 LITHE_CORE_FIXTURE_DIR - 删除 shared/contracts(28 个文件)和 shared/fixtures(295 个文件), i18n 格式样例移到 shared/i18n/fixtures - PINNED_CORE_REVISION 升到 Core main f113e9e(含 #23、#24、#25) - .gitignore 只放行 shared/i18n 和 shared/platform-feature-matrix - 资源复用清单删除 phpunit-fixture,功能矩阵删除无法本地校验的证据路径 - Note、Skill 和文档的引用改指 Core,新增 Note 记录决策
15 of 18 tasks
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.
概述
将"文件是否可作为文本打开/搜索/记录历史"的判定从扩展名白名单改为内容检测。
以前只有白名单里的后缀(.swift/.md/.json 等)才会被当作文本,导致
Package.resolved、Makefile、无后缀或未知后缀的纯文本文件被误判为二进制、无法打开或被搜索/本地历史忽略。现在改为读取内容、按控制字符判断是否为纯文本,后缀不再参与决策。
同时为后续的二进制文件查看器预留一套注册表基础设施(见下方"预留,暂无消费者")。
改动分组
A. 文本判定:扩展名白名单 → 内容检测(本 PR 的主体)
WorkspaceTextFilePolicy:删除后缀白名单,新增isPlainText(_:)(String / Data 两个重载),拒绝除 tab/换行等正常空白之外的控制字符(NUL、0x01–0x08、0x0E–0x1F、0x7F)。
workspace.rs:新增is_plain_text,与 Swift 侧逻辑逐位对齐;read_file与 search路径改用内容检测,search 的大小上限检查保持在读取内容之前。
history.rs:record记录前做纯文本校验;并先 stat 判断大小再读取内容,避免把超限的大文件整个读进内存。
ProjectHistoryFeatureModel/LocalHistoryService:移除isReadableTextFile预过滤,统一交由核心层判定。
B. 二进制查看器注册表(预留基础设施,暂无消费者)
BinaryFileViewerRegistry:支持按 magic signature 或后缀注册查看器,magic 优先于后缀;默认拒绝(不注册任何查看器时,对二进制文件的行为与改动前一致)。
FileStorage/MacFileStorage新增readPrefix(from:byteCount:),用于读取文件头。AppServices→MacServiceContainer→AppModel→DocumentFeatureModel。C. 无关清理
CodeEditorView:移除NSLayoutManagerDelegateconformance 上多余的@preconcurrency。与本 PR 主题无关,顺手清理。
测试(均在本地执行,全部通过)
swift build:通过。swift test:59 个测试 / 4 个套件全部通过,含更新后的WorkspaceTextFilePolicy与BinaryFileViewerRegistry用例(magic 优先、后缀回退、默认拒绝)。cargo test(lithe-core):34/34 通过,含新增的"未知后缀纯文本可被搜索/读取、二进制文件被拒绝"用例。