Bug: aliases & nested keys unexpected behavior
まだ誰も着手していません。
評価
調査の方向性
エイリアスを有効にした状態で、提供されている YAML.load の再現コードを実行し、Psych がエイリアスを含むネストしたハッシュをどのように表現しているかを追跡します。観測されたオブジェクト共有を YAML のエイリアスのセマンティクスと比較します。意図した挙動でない場合はリグレッションテストを追加して修正し、意図した挙動である場合は明確に文書化できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Description
Today I encountered a rather weird bug in my project, and tracked it down to how YAML handles nested keys with aliases. I noticed how changing a specific key in a Hash from YAML.load(_file) would change multiple values instead.
Given that the YAML.load(_file) method returns a Hash, changing one specific key of that Hash should not change any other key. Or at least that is the behavior I'm expecting. I couldn't find any documentation regarding this odd behavior.
I have only observed this odd behavior with nested keys, not 'normal' keys as demonstrated below.
Steps to reproduce
require 'yaml'
yaml = <<YAML
alias: &alias
normal_value: 404
nested:
value: 404
some_key:
<<: *alias
another_key:
<<: *alias
YAML
content = YAML.load(yaml, aliases: true, symbolize_names: true)
puts "========== BEFORE =========="
pp content
content[:alias][:normal_value] = 999
content[:alias][:nested][:value] = 999
puts "========== AFTER =========="
pp content
When running this script, I'm getting the following output:
========== BEFORE ==========
{alias: {normal_value: 404, nested: {value: 404}}, some_key: {normal_value: 404, nested: {value: 404}}, another_key: {normal_value: 404, nested: {value: 404}}}
========== AFTER ==========
{alias: {normal_value: 999, nested: {value: 999}}, some_key: {normal_value: 404, nested: {value: 999}}, another_key: {normal_value: 404, nested: {value: 999}}}
Notice how the nested value is modified in both some_key and another_key, while the normal value is not.
Machine details
- Apple M3 Macbook Air
- Reproduced on: "ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin24]", "ruby 3.4.0dev (2024-12-25 master f450108330) +PRISM [arm64-darwin24]"
- 主要言語
- Ruby
- スター
- 597
- フォーク
- 223
- 平均マージ
- 6時間 8分
- マージ済み PR(30日)
- 2
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 が 26 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 55/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 68/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
betagouv/conseillers-entreprises#4720 ·
メンテナーはふだん 3 日以内に返信
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
zerocracy/judges-action#2692 · コメント 1 件 ·
メンテナーはふだん 6 日以内に返信
-
agent:triaged bug bughunt pm:bundler priority:p1
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
SocketDev/socket-patch#896 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
eurosky-social/eu-haul#32 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
e0ipso/self-review#171 ·
メンテナーはふだん 1 日以内に返信