Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Psych::Nodes::Scalar::LITERAL ignored in encode_with?

未关闭
#673 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
ruby
领域
backend

调研方向

首先使用自定义类的 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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ruby/psych 的其他 Issue

查看 ruby/psych 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。