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

Already on GitHub? Sign in to your account

Psych.dump throws ArgumentError when given a string that looks like a timestamp but isn't #82

Closed
rsutphin opened this Issue Sep 11, 2012 · 2 comments

Comments

2 participants
Contributor

rsutphin commented Sep 11, 2012

Psych.dump will refuse to serialize a string value which has the form of an ISO8601 timestamp but which does not represent a valid time. E.g.:

1.9.3p194 :006 > Psych.dump('9333-93-93T93:93:93')
ArgumentError: argument out of range
    from /Users/rsutphin/.rvm/gems/ruby-1.9.3-p194@tmp/gems/psych-1.3.4/lib/psych/scalar_scanner.rb:111:in `utc'
    from /Users/rsutphin/.rvm/gems/ruby-1.9.3-p194@tmp/gems/psych-1.3.4/lib/psych/scalar_scanner.rb:111:in `parse_time'
    from /Users/rsutphin/.rvm/gems/ruby-1.9.3-p194@tmp/gems/psych-1.3.4/lib/psych/scalar_scanner.rb:48:in `tokenize'
    from /Users/rsutphin/.rvm/gems/ruby-1.9.3-p194@tmp/gems/psych-1.3.4/lib/psych/visitors/yaml_tree.rb:242:in `visit_String'
    from /Users/rsutphin/.rvm/gems/ruby-1.9.3-p194@tmp/gems/psych-1.3.4/lib/psych/visitors/yaml_tree.rb:103:in `accept'
    from /Users/rsutphin/.rvm/gems/ruby-1.9.3-p194@tmp/gems/psych-1.3.4/lib/psych/visitors/yaml_tree.rb:67:in `push'
    from /Users/rsutphin/.rvm/gems/ruby-1.9.3-p194@tmp/gems/psych-1.3.4/lib/psych.rb:242:in `dump'
    from (irb):6
    from /Users/rsutphin/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>'

This happens with both Psych 1.3.2 and 1.3.4 (the latest released version as of this writing).

While I agree that values like the one in the example are weird, it doesn't seem like a serialization library ought to express an opinion. Would it be reasonable to fall back to treating the value as a string if it isn't a valid time? I could provide a pull request for this if so.

@rsutphin rsutphin added a commit to rsutphin/psych that referenced this issue Sep 11, 2012

@rsutphin rsutphin Ignore bad timestamps. #82.
If something looks like a timestamp but has an invalid component,
treat it as a string instead of throwing an ArgumentError.
0c478a1
Owner

tenderlove commented Sep 11, 2012

Yes, this is a bug. Please send a PR and I'll merge! Thanks.

Contributor

rsutphin commented Sep 11, 2012

Handled by #83.

@rsutphin rsutphin closed this Sep 11, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment