[CXX-2016] Invalid json value returned Created: 10/May/20 Updated: 11/Dec/20 Resolved: 02/Nov/20 |
|
| Status: | Closed |
| Project: | C++ Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Rui Sebastiao | Assignee: | Samantha Ritter (Inactive) |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||
| Description |
|
I'm using the mongocxx (v3) driver in my project to store the app settings in the mongodb. While working in windows everything seems to work well. But now that i'm testing in linux i have noticed some problems that i cannot understand why are happening. i have the following function to retrieve the app settings:
the output: testing:{ "x" : 1.0 } , "appid" : "5ea8a4192483621670ffeb2b", "value" : 1,1000000000000000888 } [![In the database i have:][1]][1] [1]: https://i.stack.imgur.com/6eE8H.png ::tojson returns a string with a comma instead of a dot in the decimal separator witch obviously is an invalid JSON document. ... "value" : 1,1000000000000000888 } the workaround is to change my local to en_US, but shouldn't the returned string be independent of the locale? |
| Comments |
| Comment by Samantha Ritter (Inactive) [ 02/Nov/20 ] | ||||||||||||||||
|
Closing this ticket as CDRIVER-3812 will track the bug fix. | ||||||||||||||||
| Comment by Samantha Ritter (Inactive) [ 02/Nov/20 ] | ||||||||||||||||
|
Thank you for that information. You're correct that there is indeed a bug in the JSON parsing code! The bug is actually in the C driver (which the C++ driver wraps) and is detailed in this ticket: https://jira.mongodb.org/browse/CDRIVER-3812 The heart of the problem is that we are delegating some of the string conversion work to the `printf` function, which obeys locale rules and will use a comma separator instead of a decimal point if that's the convention in your locale. We should not be relying on that to produce valid JSON. As a workaround until the bug gets fixed, I would recommend that you manually change your locale to something that uses decimal point separators. If you'd like, you can scope the locale change very narrowly, so it only applies to the code in question:
Since we have arrived at the root cause of this ticket, I am going to close it. Please follow CDRIVER-3812 for the status of the bug fix, and please don't hesitate to open another ticket if you experience any other issues. Thank you, Samantha Ritter | ||||||||||||||||
| Comment by Roland Deschain [ 29/Sep/20 ] | ||||||||||||||||
|
Alright, I extended your example program with a call to std::locale() and this reproduces it.
de_DE is my user locale and seems to be loaded via some means in my real code (not sure why yet). | ||||||||||||||||
| Comment by Roland Deschain [ 29/Sep/20 ] | ||||||||||||||||
|
I experience the exact same problem right now. Interestingly, when running your example as a mini test-program, everything is fine. But when I add those lines to my actual code, the dot becomes a comma. I will try to find out what the reason is so you can reproduce it, too. | ||||||||||||||||
| Comment by Samantha Ritter (Inactive) [ 22/Jul/20 ] | ||||||||||||||||
|
Hi rui.sebastiao@dreamforit.com, Thanks for opening this ticket! I have not been able to reproduce this behavior. When I write this example program, the output uses a period:
Could you please tell me what your locale was before you changed it to en_US? Thanks! |