Question

Look at this case:

ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]

irb(main):006:0> YAML::ENGINE.yamler = "psych"
=> "psych"

irb(main):007:0> '8902-20-13'.to_yaml
ArgumentError: invalid date
from /usr/local/lib/ruby/1.9.1/date.rb:1022:in `new_by_frags'
from /usr/local/lib/ruby/1.9.1/date.rb:1046:in `strptime'
from /usr/local/lib/ruby/1.9.1/psych/scalar_scanner.rb:45:in `tokenize'
from /usr/local/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:191:in `visit_String'
from /usr/local/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:63:in `accept'
from /usr/local/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:36:in `<<'
from /usr/local/lib/ruby/1.9.1/psych.rb:165:in `dump'
from /usr/local/lib/ruby/1.9.1/psych/core_ext.rb:13:in `psych_to_yaml'

irb(main):008:0> YAML::ENGINE.yamler = "syck"
=> "syck"

irb(main):009:0> '8902-20-13'.to_yaml
=> "--- \"8902-20-13\"\n"

When I'm using the psych parser and I need to format a string that vaguely resembles a date, it throws an exception, because he thinks this is a date string. Using syck this problem does not occur.

Anyone have any idea?

Was it helpful?

Solution 2

As @matt had mentioned, the answer is this pull request: https://github.com/ruby/ruby/commit/9f688d53c2b5af5960d1e8d8fb09b26aa9d8b5f9

OTHER TIPS

Psych is pretty much independent of Syck, and I don't think authors of Psych are interested in being bug-compatible with Syck. I think they implement different versions of the YAML specification anyway.

One workaround should be to put strings around the date-like-numbers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top