You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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=<<YAMLalias: &alias normal_value: 404 nested: value: 404some_key: <<: *aliasanother_key: <<: *aliasYAMLcontent=YAML.load(yaml,aliases: true,symbolize_names: true)puts"========== BEFORE =========="ppcontentcontent[:alias][:normal_value]=999content[:alias][:nested][:value]=999puts"========== AFTER =========="ppcontent
When running this script, I'm getting the following output:
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
When running this script, I'm getting the following output:
Notice how the nested value is modified in both
some_key
andanother_key
, while the normal value is not.Machine details
The text was updated successfully, but these errors were encountered: