Skip to content

[6120] 修复插入参考文献时 bib 文件路径含中文导致解析失败的问题 - #4723

Merged
MoonL79 merged 3 commits into
mainfrom
da/6120/bib_chinese_path
Oct 16, 2026
Merged

MoonL79 merged 3 commits into
mainfrom
da/6120/bib_chinese_path

Conversation

@MoonL79

@MoonL79 MoonL79 commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

问题描述

在 Mogan 中插入参考文献时,如果 .bib 文件路径(或当前文档所在路径)包含中文字符,会导致预览失败、提示红字「文件不存在」且底部主按钮被禁用无法插入。

原因分析

  1. Scheme 表达式转义错误:BibliographyDialogBridge::requestPreview 构造 Scheme 调用表达式时,对路径参数误使用了 qt_scheme_quote。该函数内部将 UTF-8 路径转为 Cork 编码,导致中文字符被转换为 <less>#XXXX<gtr> 十六进制逃逸序列。Scheme 侧通过 url-exists? 探测文件系统时无法找到该路径,返回 "not_found" 与「文件不存在」,进而使 QML 弹窗中的【插入】按钮被置灰禁用。
  2. 二次解码破坏:cpp_bibliography_dialog 中初始化 bibBridge 与 initialFile 时,对已经是标准 UTF-8 编码的 doc_dir 与 file 误调用了 cork_to_utf8,破坏了中文路径。

修复方案

  1. 将 BibliographyDialogBridge::requestPreview 中构造 Scheme 表达式的 qt_scheme_quote(file) 替换为 qt_scheme_quote_utf8(file),确保路径以原生 UTF-8 格式传递给 Scheme 解释器。
  2. 消除 cpp_bibliography_dialog 中对 doc_dir 与 file 的 cork_to_utf8 二次解码破坏,直接调用 utf8_to_qstring。
  3. 增加 TeXmacs/tests/6120.scm 集成测试,验证包含中文路径的 bib 文件能正常解析出有效的语法树,并对比测试 Bug 复现特征。
  4. 在 tests/Plugins/Qt/qt_utilities_test.cpp 中补充 qt_scheme_quote_utf8 对中文路径保留原生 UTF-8 的单元测试。

@PinkMagicFly PinkMagicFly left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@MoonL79
MoonL79 merged commit 4bfb89e into main Oct 16, 2026
6 checks passed
@MoonL79
MoonL79 deleted the da/6120/bib_chinese_path branch October 16, 2026 02:28
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