Repository navigation
fix(text): 修复 YAML 块样式序列化改写非换行分隔符 - #356
openjiuwen-sync-bot[bot] wants to merge 1 commit into
Conversation
|
zxy12_zxy seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
head_sha: 变更摘要本次 PR 修复了 主要改动
|
|
head_sha: 代码审查✅ 未发现问题 |
The block-style representer split multi-line strings with str.splitlines(), which also breaks on form feed, vertical tab, NEL and the Unicode line/paragraph separators. Those characters were silently rewritten to \n before reaching the emitter, so reloading the profile changed its text. Split on \n alone, and emit strings containing the separators that YAML's reader treats as line breaks in double-quoted style so they round-trip faithfully. Signed-off-by: zxy12_zxy <419500457@qq.com>
c4a68a1 to
ff7927a
Compare
|
head_sha: [P2] 多行 profile 保存时仍会丢掉行末分隔符。 split("\n") 保留了行内字符,但随后调用的 line.rstrip() 会删除行末的垂直制表符、换页符和 U+001C– |
Paired: GitHub #356 ↔ GitCode !251
问题
yaml_io._str_representer用str.splitlines()拆分多行字符串,而splitlines()除了\n还会按垂直制表符、换页符、文件/组分隔符、NEL(U+0085) 以及 U+2028/U+2029 切分。这些字符在进入 emitter 之前就被改写成了\n,导致 profile 序列化后重新加载时文本内容发生变化。修复
\n拆分,保留行内的其他分隔符。\N/\L/\P;其余分隔符由 emitter 自动回退双引号并正确转义。\n拆分时结尾空串会保留最终换行,因此以换行结尾的字符串不会多出空行(相对原实现的回归已修复)。tests/foundation/text/test_yaml_io.py,覆盖块样式、垂直制表符、换页符、文件/组/记录分隔符、NEL(含不带换行的情况)、U+2028/U+2029、结尾换行、行尾空白与单行字符串,共 10 个用例。验证
ruff check/ruff format --check通过pytest tests/foundation/text/test_yaml_io.py10 passedmain逐字符对比:上述分隔符在main上均被改写为\n,本 PR 修复为无损往返