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

Some strings that look like date/timestamps are not quoted when dumped #676

Open
notEthan opened this issue Jul 15, 2024 · 0 comments
Open

Comments

@notEthan
Copy link

notEthan commented Jul 15, 2024

Timestamps for which Time.new raises an ArgumentError are not quoted by YAML.safe_dump (and YAML.dump - same result), leading to Psych::DisallowedClass when trying to load them.

A valid timestamp works fine and ends up a quoted string:

YAML.safe_dump("1990-12-31T15:59:60-23:00")
# => "--- '1990-12-31T15:59:60-23:00'\n"
YAML.safe_load(YAML.safe_dump("1990-12-31T15:59:60-23:00"))
# => "1990-12-31T15:59:60-23:00"

But a string that looks like a timestamp but is not valid ends up dumped unquoted, looking like a YAML timestamp which safe_load refuses:

# month 13 invalid
YAML.safe_dump("1990-13-31T15:59:60-23:00")
# => "--- 1990-13-31T15:59:60-23:00\n"

>> YAML.safe_load(YAML.safe_dump("1990-13-31T15:59:60-23:00"))
# .../gems/psych-5.1.2/lib/psych/class_loader.rb:99:in `find': Tried to load unspecified class: Time (Psych::DisallowedClass)
#   from .../gems/psych-5.1.2/lib/psych/class_loader.rb:28:in `load'
#   from .../gems/psych-5.1.2/lib/psych/scalar_scanner.rb:116:in `parse_time'
#   from .../gems/psych-5.1.2/lib/psych/scalar_scanner.rb:59:in `tokenize'
#   from .../gems/psych-5.1.2/lib/psych/visitors/to_ruby.rb:65:in `deserialize'
#   from .../gems/psych-5.1.2/lib/psych/visitors/to_ruby.rb:130:in `visit_Psych_Nodes_Scalar'
#   from .../gems/psych-5.1.2/lib/psych/visitors/visitor.rb:30:in `visit'
#   from .../gems/psych-5.1.2/lib/psych/visitors/visitor.rb:6:in `accept'
#   from .../gems/psych-5.1.2/lib/psych/visitors/to_ruby.rb:35:in `accept'
#   from .../gems/psych-5.1.2/lib/psych/visitors/to_ruby.rb:320:in `visit_Psych_Nodes_Document'
#   from .../gems/psych-5.1.2/lib/psych/visitors/visitor.rb:30:in `visit'
#   from .../gems/psych-5.1.2/lib/psych/visitors/visitor.rb:6:in `accept'
#   from .../gems/psych-5.1.2/lib/psych/visitors/to_ruby.rb:35:in `accept'
#   from .../gems/psych-5.1.2/lib/psych.rb:334:in `safe_load'

Likewise with a date:

# Feb 31 invalid
YAML.safe_dump("1990-02-31")
# => "--- 1990-02-31\n"

>> YAML.safe_load(YAML.safe_dump("1990-02-31"))
# ...gems/psych-5.1.2/lib/psych/class_loader.rb:99:in `find': Tried to load unspecified class: Date (Psych::DisallowedClass)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant