Psych::Nodes::Scalar::LITERAL ignored in encode_with?
还没有人认领这个 Issue。
评估
调研方向
首先使用自定义类的 encode_with 方法,通过设置 coder.scalar、coder.tag 和 Psych::Nodes::Scalar::LITERAL,重现短 YAML 输出和长 YAML 输出。比较 Psych 如何处理标量长度和转义的换行符,然后确定错误的是文档所述的行为还是生成的输出。完成标准是解释清楚原因,并确定一项有针对性的回归测试或文档变更。
由索引模型根据 Issue 内容生成。
描述
This could just me, but I really lost and I don't understand why this works this way.
I have a big YAML with various string values. One of them is an encoded file content which is nice for machine consumption but I want to show that as a literal for human beings.
I created a separate class for those values and I added an encode_with method.
def encode_with( coder )
coder.scalar = @str
coder.tag = "!file_content"
coder.style = Psych::Nodes::Scalar::LITERAL
end
When the value is short then it works as expected but if it is longer then output is still quoted.
---
hello: world
short: !file_content |
TEST_DOCKER_IMAGE="foobar/image:1.2.3-r4"
long: !file_content "!\n! %[CONN_NAME]\n!\nneighbor %[REMOTE_ADDRESS] remote-as %[REMOTE_ASN]\nneighbor
%[REMOTE_ADDRESS] description %[CONN_NAME]\naddress-family ipv6\n\tneighbor %[REMOTE_ADDRESS]
activate\n\tneighbor %[REMOTE_ADDRESS] soft-reconfiguration inbound\n\tneighbor
%[REMOTE_ADDRESS] prefix-list ipv6_ranges in\n\tneighbor %[REMOTE_ADDRESS] prefix-list
ipv6_ranges out\n\tneighbor %[REMOTE_ADDRESS] route-map add_extra_hop in\n\tneighbor
%[REMOTE_ADDRESS] route-map no_advertise_self out\nexit-address-family\n"
The documentation is quite scarce about this topic. Do I miss something? Or is this a bug in Psych?
- 主要语言
- Ruby
- 星标
- 597
- 派生
- 223
- 平均合并
- 11 小时 23 分钟
- 30 天内合并 PR
- 3
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ruby/psych 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
-
Documentation
难度 1/5 1 小时以内 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 55/100
-
难度 4/5 3-5 天 新手友好度 68/100
-
难度 4/5 3-5 天 新手友好度 52/100
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
-
ai-generated
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 75/100
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
hanami/hanami-cli#449 ·
-
难度 2/5 1-3 小时 新手友好度 82/100
hanami/hanami-router#310 ·