[ruby/psych] Fix RestrictedYAMLTree allowing the Symbol class should allow all symbols

Ref: https://github.com/ruby/psych/pull/495

That's how it works for `safe_load`:
```ruby
>> YAML.safe_load(':foo', permitted_classes: [Symbol])
=> :foo
```

So `safe_dump` should mirror that.

https://github.com/ruby/psych/commit/592a75a656
This commit is contained in:
Jean Boussier 2023-01-22 09:04:11 -05:00 коммит произвёл git
Родитель d623210811
Коммит 8fded5f5d1
2 изменённых файлов: 7 добавлений и 4 удалений

Просмотреть файл

@ -568,7 +568,7 @@ module Psych
raise BadAlias, "Tried to dump an aliased object"
end
unless @permitted_classes[target.class]
unless Symbol === target || @permitted_classes[target.class]
raise DisallowedClass.new('dump', target.class.name || target.class.inspect)
end
@ -576,7 +576,7 @@ module Psych
end
def visit_Symbol sym
unless @permitted_symbols[sym]
unless @permitted_classes[Symbol] || @permitted_symbols[sym]
raise DisallowedClass.new('dump', "Symbol(#{sym.inspect})")
end

Просмотреть файл

@ -419,12 +419,15 @@ eoyml
end
def test_safe_dump_symbols
assert_equal Psych.dump(:foo), Psych.safe_dump(:foo, permitted_classes: [Symbol])
assert_equal Psych.dump(:foo), Psych.safe_dump(:foo, permitted_symbols: [:foo])
error = assert_raise Psych::DisallowedClass do
Psych.safe_dump(:foo, permitted_classes: [Symbol])
Psych.safe_dump(:foo)
end
assert_equal "Tried to dump unspecified class: Symbol(:foo)", error.message
assert_match(/\A--- :foo\n(?:\.\.\.\n)?\z/, Psych.safe_dump(:foo, permitted_classes: [Symbol], permitted_symbols: [:foo]))
assert_match(/\A--- :foo\n(?:\.\.\.\n)?\z/, Psych.safe_dump(:foo, permitted_symbols: [:foo]))
end
def test_safe_dump_aliases