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

use YAML.unsafe_load instead of YAML.load to maintain compatibility #178

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kangaechu
Copy link

Environment

  • Ruby 3.2.2
  • Bricolage 6.0.0beta7

Details

I got an following error.

eval error: /home/user/app/importer/config/variable.yml: config file syntax error: Tried to load unspecified class: Date

importer/config/variable.yml:

<%
require 'date'

target_day = ENV['TARGET_DAY']
today = Date.parse(target_day)
%>
target_day: <%= target_day %>

Since Ruby 3.1.0, Psych has been updated to 4.0.0.
Psych 4.0.0 has incompatible changes.
In Psych 4.0.0, YAML.load uses Psych.safe_load internally.
Previous versions of Psych.load can also be used with Psych.unsafe_load.
Psych.safe_load is a safer way to load YAML data than Psych.load.
By default, Psych.safe_load only converts objects of the following classes: TrueClass, FalseClass, NilClass, Numeric, String, Array, and Hash.
Psych.safe_load also does not allow the use of YAML aliases.
Because of this difference between Psych.load and Psych.safe_load, YAML data that was previously loadable may no longer load.
Therefore, YAML.unsafe_load is used instead of YAML.load to maintain compatibility.

https://secret-garden.hatenablog.com/entry/2021/05/23/200803 (Japanese)

Since Ruby 3.1.0, Psych has been updated to 4.0.0.
Psych 4.0.0 has incompatible changes.
In Psych 4.0.0, Psych.load uses Psych.safe_load internally.
Previous versions of Psych.load can also be used with Psych.unsafe_load.
Psych.safe_load is a safer way to load YAML data than Psych.load.
By default, Psych.safe_load only converts objects of the following classes: TrueClass, FalseClass, NilClass, Numeric, String, Array, and Hash.
Psych.safe_load also does not allow the use of YAML aliases.
Because of this difference between Psych.load and Psych.safe_load, YAML data that was previously loadable may no longer load.
Therefore, YAML.unsafe_load is used instead of YAML.load to maintain compatibility.
@nekketsuuu
Copy link
Contributor

How about quoting a value on the YAML side? Like,

target_day: "<%= target_day %>"

Or, did you use target_day variable as a Date instance instead of String?

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.

2 participants