jbeder / yaml-cpp

A YAML parser and emitter in C++
MIT License
5.18k stars 1.87k forks source link

Numbers are emitted wrongly under non-C locales. #1282

Closed Botje closed 4 months ago

Botje commented 6 months ago

From a question on StackOverflow:

int main(){
  std::locale::global(std::locale(""));
  YAML::Emitter out;
  out << 2112;
  std::cout << "Emitter for 2112 = " << out.c_str() << '\n';
}

When run under LC_ALL=en_US.UTF-8 this produces 2,112 which parses as a string "2,112". Under LC_ALL=nl_BE.UTF-8 this becomes 2.112, which is interpreted by other parsers as a floating point number.

tibyo commented 6 months ago

In my case, the line std::locale::global(std::locale("")); is not required to produce this behaviour. I am not setting the global locale anywhere in my project*, the only reference to locale I make is the use of std::format("{:L} ... but still the integer 2024 is being rendered as "2,024" by yaml-cpp.

SGSSGene commented 4 months ago

Yes, definitely a bug. Can @Botje and/or @tibyo confirm that #1297 fixes this issue?