Skip to content

Commit

Permalink
Permit Time class loading from YAML.
Browse files Browse the repository at this point in the history
Since Psych 4.0, the `safe_load` is used as default loading mechanism.
There are just a few permitted classes and `Time` is not one of them
[[1]]. This results it test failure:

~~~
Error: test_converting_to_yaml(DocumentTest::TestSimpleConventionallyNamedDocument): Psych::DisallowedClass: Tried to load unspecified class: Time
~~~

Please also note that in YAML specs 1.2, the `timestamp` is not
listed as supported tag anymore [[2]].

Given that:

1) ronn-ng does not provide any supported way of loading the serialized
   YAML.
2) The `to_yaml` does not appear to be used internally/externally
   anywhere.
3) If there were users of this functionality, it would have been already
   know, reported and fixed at this moment.

The best course of action is fixing the test case by listing the `Time`
as valid class for parsing.

Fixes apjanke#80

[1]: https://docs.ruby-lang.org/en/master/Psych.html#method-c-safe_load
[2]: yaml/yaml-spec#268
  • Loading branch information
voxik committed Aug 30, 2022
1 parent 5c3da40 commit 25158fa
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion test/test_ronn_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def canonicalize(text)
'toc' => [['NAME', 'NAME']],
'organization' => nil,
'manual' => nil
}, YAML.load(@doc.to_yaml))
}, YAML.load(@doc.to_yaml, permitted_classes: [Time]))
end

test 'converting to json' do
Expand Down

1 comment on commit 25158fa

@boutil
Copy link

@boutil boutil commented on 25158fa Nov 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi!
Using load with the permitted_classes named parameter would not work with ruby3.0. I think it would be better to use safe_load instead.

Please sign in to comment.