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

Ruby Psych fails to parse correctly formatted YAML dates #8

Closed
ronaldtse opened this issue Jan 13, 2022 · 1 comment
Closed

Ruby Psych fails to parse correctly formatted YAML dates #8

ronaldtse opened this issue Jan 13, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@ronaldtse
Copy link
Contributor

metadata:
  title: 'Resolutions of the CGPM: 1st meeting'
  date: 1889-09-28
  source: BIPM - Pavillon de Breteuil
  url: https://www.bipm.org/en/CGPM/db/1
resolutions:
- dates:
  - 1889-09-28

The 1889-09-28 date instances will fail on YAML.load like this:

Failure/Error: YAML.load_file(Pathname.new(f).expand_path.to_s)

Psych::DisallowedClass:
  Tried to load unspecified class: Date
# (eval):2:in `date'
# ./spec/bipm/data/importer/cgpm_spec.rb:8:in `block (2 levels) in <top (required)>'
# ./spec/bipm/data/importer/cgpm_spec.rb:6:in `map'
# ./spec/bipm/data/importer/cgpm_spec.rb:6:in `block in <top (required)>'
# ./spec/bipm/data/importer/cgpm_spec.rb:3:in `<top (required)>'

The reason is the Psych YAML parser at Ruby has the following bug but it was never fixed, for 6 years!
ruby/psych#262

In that ticket some suggested that only "invalid dates" will raise this issue, but the case is all dates will cause this issue. This is frustrating because the YAML spec does support the "Date" type.

Simply speaking:

irb(main):004:0> YAML.load("1900-01-01")
~/.rbenv/versions/3.1.0/lib/ruby/3.1.0/psych/class_loader.rb:99:in `find': Tried to load unspecified class: Date (Psych::DisallowedClass)
@ronaldtse ronaldtse added the bug Something isn't working label Jan 13, 2022
@ronaldtse
Copy link
Contributor Author

Going to change the data to use quoted strings for dates for now until ruby/psych#262 is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant