Why is there a difference in the behavior of YAML parsers (syck and psych)?

Look at this case:

ruby 1.9.2p0 (2010-08-18 version 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 use a parser and I need to format a string that is vaguely like a date, it throws an exception because it considers it to be a date string. Using syck this problem does not occur.

Does anyone have an idea?

+4
source share
2 answers
0
source

Psych is largely independent of Syck, and I don’t think that the authors of Psych are interested in Syck compatibility error. I think they still use different versions of the YAML specification.

A workaround should be to put strings around numbers like date.

+2
source

Source: https://habr.com/ru/post/1389715/


All Articles