Repository navigation
[6120] 修复插入参考文献时 bib 文件路径含中文导致解析失败的问题 - #4723
Merged
Merged
Conversation
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.
问题描述
在 Mogan 中插入参考文献时,如果 .bib 文件路径(或当前文档所在路径)包含中文字符,会导致预览失败、提示红字「文件不存在」且底部主按钮被禁用无法插入。
原因分析
BibliographyDialogBridge::requestPreview构造 Scheme 调用表达式时,对路径参数误使用了qt_scheme_quote。该函数内部将 UTF-8 路径转为 Cork 编码,导致中文字符被转换为<less>#XXXX<gtr>十六进制逃逸序列。Scheme 侧通过url-exists?探测文件系统时无法找到该路径,返回"not_found"与「文件不存在」,进而使 QML 弹窗中的【插入】按钮被置灰禁用。cpp_bibliography_dialog中初始化bibBridge与initialFile时,对已经是标准 UTF-8 编码的doc_dir与file误调用了cork_to_utf8,破坏了中文路径。修复方案
BibliographyDialogBridge::requestPreview中构造 Scheme 表达式的qt_scheme_quote(file)替换为qt_scheme_quote_utf8(file),确保路径以原生 UTF-8 格式传递给 Scheme 解释器。cpp_bibliography_dialog中对doc_dir与file的cork_to_utf8二次解码破坏,直接调用utf8_to_qstring。TeXmacs/tests/6120.scm集成测试,验证包含中文路径的 bib 文件能正常解析出有效的语法树,并对比测试 Bug 复现特征。tests/Plugins/Qt/qt_utilities_test.cpp中补充qt_scheme_quote_utf8对中文路径保留原生 UTF-8 的单元测试。