Bug: aliases & nested keys unexpected behavior
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Esegui la riproduzione fornita di YAML.load con gli alias abilitati, quindi traccia come Psych rappresenta gli hash annidati con alias. Confronta la condivisione degli oggetti osservata con la semantica degli alias YAML; il lavoro è concluso quando il comportamento è stato corretto con una copertura di regressione oppure documentato chiaramente se intenzionale.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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]"
- Lingua principale
- Ruby
- Stelle
- 597
- Fork
- 223
- Merge medio
- 6h 8m
- PR unite (30g)
- 2
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ruby/psych
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Documentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
-
Psych.dump raises Encoding::CompatibilityError for UTF-16/UTF-32 stringsForse già presa @Halvanhelv l’ha presa 26 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 55/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 68/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
Issue simili
-
revoir les metions de la DGEAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
betagouv/conseillers-entreprises#4720 ·
I maintainer di solito rispondono entro 3 giorni
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
zerocracy/judges-action#2692 · 1 commento ·
I maintainer di solito rispondono entro 6 giorni
-
agent:triaged bug bughunt pm:bundler priority:p1
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
SocketDev/socket-patch#896 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Add Catalan (ca) translationAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
eurosky-social/eu-haul#32 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
e0ipso/self-review#171 ·
I maintainer di solito rispondono entro 1 giorno