Roundtrip not possible when using identical array twice
まだ誰も着手していません。
評価
調査の方向性
まず YAML.load(YAML.dump({ a: a, b: a })) の例を再現し、Psych の YAML.load、YAML.dump、エイリアス処理のパスを調査します。Issue ではファイルもテストも指定されておらず、ダンプまたはロードを変更すべきかも定義されていないため、実装前に受け入れ基準を確立する必要があります。
索引モデルが issue の本文から書いたものです。
説明
tl;dr:
require "yaml"
a = [1,2,3]
YAML.load(YAML.dump({ a: a, b: a }))
# raises 'Psych::Visitors::NoAliasRuby#visit_Psych_Nodes_Alias': Alias parsing was not enabled. To enable it, pass `aliases: true` to `Psych::load` or `Psych::safe_load`. (Psych::AliasesNotEnabled)
Long form
Hey there, today I noticed an error that surprised me quite a lot. Essentially as soon as you include the same array twice in a structure that you dump through Psych, it will not be loadable using a default YAML.load. You'd have to pass specific options to make it loadable.
The problem is that dump will generate YAML in the form:
---
:a: &1
- 1
- 2
- 3
:b: *1
This preserves the array identity for the hashes stored under a and b.
That's surprising to me. I'd have expected that if load disables certain YAML features by default, that dump would also only use those on an opt-in basis. Even worse: I don't see a setting documented that would allow me to disable the alias creation. The two fixes available to me right now:
- enable alias deserialization (which I believed to be disabled by default for security considerations; though I fail to find a source for that now)
- duplicate values in my
dumpinput to avoid alias generation
Second solution shown in code:
YAML.load(YAML.dump({ a: a, b: a.dup }))
=> {a: [1, 2, 3], b: [1, 2, 3]}
- 主要言語
- Ruby
- スター
- 597
- フォーク
- 223
- 平均マージ
- 11時間 23分
- マージ済み PR(30日)
- 3
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
TheOdinProject/curriculum#31417 · コメント 2 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
glossarist/glossarist-ruby#238 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
palladius/rails8-app-on-gcp#145 ·