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

Can we please get a "raw" loader?

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

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
ruby, yaml
领域
tooling

调研方向

从 YAML.load、safe_load 和建议的入口点 Psych.set_parse_mode 开始,然后比较 issue 中的两个 YAML 示例。定义 raw mode 的转换规则,以及它应如何区别于 native-object mode;完成意味着已明确指定所请求的 hash-tree 输出,并由实现测试覆盖。

由索引模型根据 Issue 内容生成。

描述

There are times when we need to load a YAML file but for various reasons, we do not want or care about the serialization/native dataclass conversions. We want to load the data in as a hash-tree object, as if the object classifier were not there.

Now it seems to me based on the long discussion related to the safe_load method, that safe_load does not, in fact, do what is requested here. It seems to me that several sane voices were a bit shuoted down in that discussion. But whatever.

What is needed is essentially to load YAML files as if they were dumb JSON files. As if the following code were implemented before the #load

yamltext = File.read("somefile","r")
yamltext.sub!(/^--- \!.*$/,'---')
purehash = YAML.load(yamltext)

Given the following YAML:

--- !ruby/object:Some::Custom::Type::User::Has::No::Gem::For
 node: "string"
 array:
  - "string"
  - unquoted text
  - "12.5"
  - 12.5
  - subarray:
      option: true
      nottrue: "false"

We get back from #load:

{"node"=>"string", "array"=>["string", "unquoted text", "12.5", 12.5, {"subarray"=>{"option"=>true, "nottrue"=>"false"}}]}

I propose an implementation that is cleaner, that uses YAML.load() but based on the parser-personality. The personalities might be a kind of a "raw" mode and "native-object" mode. Raw mode only sees Hash, Array, String. Native-object mode also sees numeric, boolean (and..?)

Psych.set_parse_mode(:native_object_conversion)
purehash=YAML.load(yamltext)

Produces the inspected output, above. Whereas:

Psych.set_parse_mode(:no_object_conversion)
purehash=YAML.load(yamltext)

produces (subtly different):

{"node"=>"string", "array"=>["string", "unquoted text", "12.5", "12.5", {"subarray"=>{"option"=>"true", "nottrue"=>"false"}}]}
主要语言
Ruby
星标
597
派生
223
平均合并
14 分钟
30 天内合并 PR
1

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

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

ruby/psych 的其他 Issue

查看 ruby/psych 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

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