Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permit Time class loading from YAML. #81

Closed
wants to merge 4 commits into from

Conversation

voxik
Copy link
Contributor

@voxik voxik commented Aug 30, 2022

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 #80

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
@voxik voxik force-pushed the yaml-load-permit-time branch from 4bc23da to 25158fa Compare August 30, 2022 07:31
@voxik
Copy link
Contributor Author

voxik commented Aug 30, 2022

Ok, now how to make this compatible with old Rubies 🤔

This is due to Ruby 3.1 + Psych 4.0 changed changed `YAML.load` to use
`safe_load` by default.
@voxik voxik force-pushed the yaml-load-permit-time branch 2 times, most recently from 16a5bdb to 78249ea Compare August 30, 2022 08:45
voxik added 2 commits August 30, 2022 10:51
This is to make the test case less poluted. Can be dropped once only
Ruby 3.1+ is supported.
This should make Rubocop happy.
@voxik voxik force-pushed the yaml-load-permit-time branch from 78249ea to 7c49ae1 Compare August 30, 2022 08:51
@voxik
Copy link
Contributor Author

voxik commented Aug 30, 2022

Ok, so finally, the test suite is passing on CI for Ruby 2.7. The older Rubies fails due to some issues installing Nokogiri. The test matrix would certainly deserve some refresh.

The PR ATM consists of 4 commits as the PR evolved. They could be squashed. Or the patch with extracted yaml_load could be dropped altogether if preferred, because this change should be reverted one day, once Ruby 3.1+ are the only supported versions.

@voxik
Copy link
Contributor Author

voxik commented Aug 30, 2022

The older Rubies fails due to some issues installing Nokogiri.

This seems to be due to some merge conflict. 0fd051e removes the Gemfile.lock, while 5c3da40 introduces it back.

The initial version a7ca51d of Gemfile.lock asserts that it should be included ....

@apjanke
Copy link
Owner

apjanke commented Jan 6, 2023

Fixed in e194bf6, I think.

@apjanke apjanke closed this Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Psych::DisallowedClass: Tried to load unspecified class: Time with Ruby 3.1 / Psych 4.0
3 participants