[前][次][番号順一覧][スレッド一覧]

ruby-changes:66220

From: Jean <ko1@a...>
Date: Mon, 17 May 2021 11:21:07 +0900 (JST)
Subject: [ruby-changes:66220] a3ceed50b8 (master): [ruby/psych] Fix symabolize_name with non-string keys

https://git.ruby-lang.org/ruby.git/commit/?id=a3ceed50b8

From a3ceed50b877e57554ec825d7fefe066c81ff0ee Mon Sep 17 00:00:00 2001
From: Jean Boussier <jean.boussier@g...>
Date: Thu, 25 Feb 2021 18:36:15 +0100
Subject: [ruby/psych] Fix symabolize_name with non-string keys

https://github.com/ruby/psych/commit/1c5c29e81f
---
 ext/psych/lib/psych/visitors/to_ruby.rb | 2 +-
 test/psych/test_psych.rb                | 7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb
index 4d98850..4de7f80 100644
--- a/ext/psych/lib/psych/visitors/to_ruby.rb
+++ b/ext/psych/lib/psych/visitors/to_ruby.rb
@@ -366,7 +366,7 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/to_ruby.rb#L366
               hash[key] = val
             end
           else
-            if !tagged && @symbolize_names
+            if !tagged && @symbolize_names && key.is_a?(String)
               key = key.to_sym
             elsif !@freeze
               key = deduplicate(key)
diff --git a/test/psych/test_psych.rb b/test/psych/test_psych.rb
index 76a3627..9eea4a0 100644
--- a/test/psych/test_psych.rb
+++ b/test/psych/test_psych.rb
@@ -371,17 +371,18 @@ class TestPsych < Psych::TestCase https://github.com/ruby/ruby/blob/trunk/test/psych/test_psych.rb#L371
     yaml = <<-eoyml
 foo:
   bar: baz
+  1: 2
 hoge:
   - fuga: piyo
     eoyml
 
     result = Psych.load(yaml)
-    assert_equal result, { "foo" => { "bar" => "baz"}, "hoge" => [{ "fuga" => "piyo" }] }
+    assert_equal result, { "foo" => { "bar" => "baz", 1 => 2 }, "hoge" => [{ "fuga" => "piyo" }] }
 
     result = Psych.load(yaml, symbolize_names: true)
-    assert_equal result, { foo: { bar: "baz" }, hoge: [{ fuga: "piyo" }] }
+    assert_equal result, { foo: { bar: "baz", 1 => 2 }, hoge: [{ fuga: "piyo" }] }
 
     result = Psych.safe_load(yaml, symbolize_names: true)
-    assert_equal result, { foo: { bar: "baz" }, hoge: [{ fuga: "piyo" }] }
+    assert_equal result, { foo: { bar: "baz", 1 => 2 }, hoge: [{ fuga: "piyo" }] }
   end
 end
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]