Bug: aliases & nested keys unexpected behavior
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Chạy bản tái hiện YAML.load được cung cấp với aliases được bật, sau đó theo dõi cách Psych biểu diễn các hash lồng nhau có aliases. So sánh việc chia sẻ đối tượng được quan sát với ngữ nghĩa alias của YAML; công việc được xem là hoàn tất khi hành vi này được sửa bằng kiểm thử hồi quy hoặc được ghi rõ trong tài liệu nếu đó là chủ đích.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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]"
- Ngôn ngữ chính
- Ruby
- Star
- 597
- Fork
- 223
- Merge trung bình
- 6 giờ 8 phút
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ruby/psych
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Documentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
-
Psych.dump raises Encoding::CompatibilityError for UTF-16/UTF-32 stringsCó thể đã có người làm @Halvanhelv đã nhận 26 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 55/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 68/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
Issue tương tự
-
Add Catalan (ca) translationĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
eurosky-social/eu-haul#32 ·
-
README configuration examples use the wrong module name and describe removed Bootstrap assetsĐang mởgood first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
benbalter/add-to-org#17 ·
-
good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
benbalter/change_agent#11 ·
-
good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
benbalter/count-org-loc#20 ·
-
good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
benbalter/sitemap-parser#33 ·