ingydotnet / yaml-libyaml-pm

Perl Binding to libyaml
http://search.cpan.org/dist/YAML-LibYAML/
33 stars 37 forks source link

Strings are not always encoded when they need to #94

Closed spidamoo closed 1 year ago

spidamoo commented 4 years ago

I encountered a problem when a string containing colons does not get encoded, e.g.:

$ perl -e 'use YAML::XS qw(Dump); print Dump({example => "2019-10-15 17:33:04"})'
---
example: 2019-10-15 17:33:04

Which is invalid YAML. I believe this should be fixed.

perlpunk commented 4 years ago

A string with a colon must only by quoted when it's followed by a space (or a linebreak) See also http://blogs.perl.org/users/tinita/2018/03/strings-in-yaml---to-quote-or-not-to-quote.html

When you say it's invalid YAML, do you have problems loading it?

spidamoo commented 4 years ago

Yup I did a little more research and indeed it does not seem to be invalid YAML per se. The problem I have is I generate OpeanAPI spec and load it into Swagger UI and Swagger does not recognise this example as a string, it says it's an OrderedMap.

perlpunk commented 4 years ago

The only thing I can think of that Swagger UI sees it as a timestamp instead of an ordinary string. It depends on what YAML types are enabled in the loader. There is currently no way in YAML::XS to quote such strings, but there will be in YAML::PP(::LibYAML), as soon as I support timestamp types.

perlpunk commented 1 year ago

Closing this as it isn't a bug