jbeder / yaml-cpp

A YAML parser and emitter in C++
MIT License
4.91k stars 1.77k forks source link

YAML octal scalars not converted to ints #1251

Open matthew-eads opened 6 months ago

matthew-eads commented 6 months ago

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

jbeder commented 5 months ago

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.

akortunov commented 3 months ago

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.

jwuttke commented 1 month ago

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.