Skip to content

[6121] 修复 BibTeX 年份含宏导致条目排序报错及 Scheme 异常穿透崩溃 - #4728

Merged
MoonL79 merged 2 commits into
mainfrom
da/6121/bib-sort-crash
Oct 16, 2026
Merged

MoonL79 merged 2 commits into
mainfrom
da/6121/bib-sort-crash

Conversation

@MoonL79

@MoonL79 MoonL79 commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

任务背景与问题分析

  1. BibTeX 年份含宏解析为复合语法树:当 BibTeX 条目年份中包含 LaTeX 宏(如 year = "{\noopsort{1973b}}1973")时,解析后在 Scheme 中作为 pair(如 '(concat (noopsort "1973b") "1973"))存在。
  2. 排序与标签计算类型假设错误:
    • bibtex-plain.scm 与 bibtex-alpha.scm 的 bib-sort-key 直接对年份执行 string-append,引发类型异常;
    • bibtex-alpha.scm 的 bib-format-label-year 直接调用 string-length,引发类型异常。
  3. 异常逃逸导致段错误崩溃:在参考文献插入对话框中,未捕获的 Scheme 异常通过 longjmp 跨越 Qt 模态事件循环与 QML 调度栈,破坏调用栈并触发段错误崩溃。

修复措施

  1. 安全净化年份字符串:
    • 在 bibtex-plain.scm 的 bib-sort-key 中使用 (bib-purify (bib-field x "year"))。
    • 在 bibtex-alpha.scm 的 bib-sort-key 与 bib-format-label-year 中使用 bib-purify 净化年份。
  2. 增强异常隔离保护:
    • 在 bibtex-bib-widgets.scm 的 bib-to-tree 中对排版过程 (bibwid-output-content t actual-style) 增加 (catch #t ...) 防御,捕获异常后返回 ("invalid" msg)。
    • 在中文字典补充对应错误提示翻译。
  3. 添加自动化回归测试:
    • 新增集成测试 TeXmacs/tests/6121.scm,验证含 \noopsort 宏条目在 plain 和 alpha 样式下的解析与排版。

@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 dd022dc into main Oct 16, 2026
5 checks passed
@MoonL79
MoonL79 deleted the da/6121/bib-sort-crash branch October 16, 2026 02:52
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.

2 participants