Skip to content

psych tries to parse a string as a date, which is just a string #42

bjoernbur opened this Issue Dec 15, 2011 · 1 comment

3 participants


I'm facing a problem with psych, that it tries to convert a normal string ("1110-15-1") into a date.
I assume the problem is the following regular expression:

      when /^\d{4}-\d{1,2}-\d{1,2}$/
        require 'date'
        Date.strptime(string, '%Y-%m-%d')

I see that the string above looks like a date but what possible ways are there to serialize a normal string with a date-like format?


/usr/lib/ruby/1.9.1/date.rb:1022:in `new_by_frags'
/usr/lib/ruby/1.9.1/date.rb:1046:in `strptime'
/usr/lib/ruby/1.9.1/psych/scalar_scanner.rb:45:in `tokenize'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:191:in `visit_String'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:63:in `accept'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:227:in `block in visit_Hash'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:225:in `each'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:225:in `visit_Hash'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:63:in `accept'
/usr/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:36:in `<<'
/usr/lib/ruby/1.9.1/psych.rb:165:in `dump'
/usr/lib/ruby/1.9.1/psych/core_ext.rb:13:in `psych_to_yaml'
@tenderlove tenderlove added a commit that closed this issue Dec 18, 2011
@tenderlove * ext/psych/lib/psych/scalar_scanner.rb: Strings that look like dates
  should be treated as strings and not dates.  Fixes #42

* test/psych/test_scalar_scanner.rb: corresponding tests.

This bug fix is still not in the RubyGems release

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.