Can we please get a "raw" loader?
还没有人认领这个 Issue。
评估
调研方向
从 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 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ruby/psych 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
-
Documentation
难度 1/5 1 小时以内 新手友好度 72/100
-
Psych.dump raises Encoding::CompatibilityError for UTF-16/UTF-32 strings可能已有人在做 @Halvanhelv 于 31 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 55/100
-
难度 4/5 3-5 天 新手友好度 68/100
-
难度 4/5 3-5 天 新手友好度 52/100
相似的 Issue
-
area/web interface
难度 2/5 1-3 小时 新手友好度 62/100
mastodon/mastodon#41009 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
-
ds-drift
难度 1/5 1 小时以内 新手友好度 76/100
we-promise/sure#4120 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 4 天内回复