summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2021-02-25 18:36:15 +0100
committerJean Boussier <jean.boussier@gmail.com>2021-02-25 18:41:51 +0100
commit1c5c29e81fd5572df2ec6cdef655b1521fd4c97e (patch)
tree2039bf0b4acf38c011fe5bfe418c5c5d79da03bf
parent091cd46b1f18d7a6465c7025f2f1d5a4f2bb70a4 (diff)
downloadpsych-1c5c29e81fd5572df2ec6cdef655b1521fd4c97e.zip
Fix symabolize_name with non-string keys
-rw-r--r--lib/psych/visitors/to_ruby.rb2
-rw-r--r--test/psych/test_psych.rb7
2 files changed, 5 insertions, 4 deletions
diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb
index 4d98850..4de7f80 100644
--- a/lib/psych/visitors/to_ruby.rb
+++ b/lib/psych/visitors/to_ruby.rb
@@ -366,7 +366,7 @@ module Psych
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 30612de..c3c04d7 100644
--- a/test/psych/test_psych.rb
+++ b/test/psych/test_psych.rb
@@ -371,17 +371,18 @@ class TestPsych < Psych::TestCase
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