Skip to content


Subversion checkout URL

You can clone with
Download ZIP


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

rsutphin opened this Issue · 2 comments

2 participants


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 referenced this issue from a commit in rsutphin/psych
@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.

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


Handled by #83.

@rsutphin rsutphin closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.