yaml-cpp icon indicating copy to clipboard operation
yaml-cpp copied to clipboard

YAML octal scalars not converted to ints

Open matthew-eads opened this issue 2 years ago • 3 comments

The 1.2.2 YAML spec indicates octal literals should be formatted as "0o123" which is annoyingly not consistent with what C++ thinks octal strings should look like (0123). The stringstream extraction currently used expects octals to have a single leading '0', not '0o'. This is used by yaml-cpp: https://github.com/jbeder/yaml-cpp/blob/eaf72053724814be3b99d38e292fca5797a57b7b/include/yaml-cpp/node/convert.h#L142-L155 Which ultimately means "0o123" cannot be converted to an int. "0123" on the other hand can be converted to an int, which is maybe not the desired behavior if strictly adhering to the 1.2 spec. Note this is true only as of YAML 1.2, version 1.1 specifies octals the opposite way 🙃. Somewhat related to treatment of booleans: #1198

matthew-eads avatar Dec 06 '23 19:12 matthew-eads

I think you're right. Probably the right behavior is to add the 0o123 format but not remove the 0123 format, since the YAML schema is allowed to be extended, and 0123 is reasonable to parse as octal.

jbeder avatar Jan 28 '24 21:01 jbeder

but not remove the 0123 format, since the YAML schema is allowed to be extended, and 0123 is reasonable to parse as octal.

According to 1.2 specs, an old format is supposed to be parsed as decimal numbers:

Octal values need a 0o prefix; e.g. 010 is now parsed with the value 10 rather than 8.

akortunov avatar Mar 07 '24 18:03 akortunov

Only a minority of YAML users are talking C. The others are completely unprepared for 010 = 8. Upstream YAML was right to correct the specs.

jwuttke avatar May 07 '24 13:05 jwuttke