#1285·eino

components/document/parser: 在 Windows 版本中,如果 core.autocrlf 设置为 true(测试数据中包含 CRLF),则 TestParser 会出错

作者: fszcd创建于 2026年9月13日更新于 2026年9月13日

描述错误

go test ./components/document/parser/ 在使用 Git 的默认 Windows 配置(core.autocrlf=true)的 Windows 主机上失败:

--- FAIL: TestParser (0.00s)
--- FAIL: TestParser/Test_default_parser (0.00s)
parser_test.go:61:
Error: Not equal:
expected: "# Title\nhello world"
actual: "# Title\r\nhello world"

根本原因

TestParser/Test_default_parser 解析了已检入的 components/document/parser/testdata/test.md 并断言其确切内容("# Title\nhello world")。使用 core.autocrlf=true - 标准 Git for Windows 安装程序的默认值 - 则工作树副本的 testdata/test.md 以 CRLF 行结束形式呈现,TextParser (正确地) 返回文件字节原文,因此断言失败。因此,测试的结果取决于贡献者的本地 git 配置,而不仅是待测代码。CI 仅在 ubuntu-latest 上运行,因此此问题在上游是看不到的。