open-source-parsers / open-source-parsers/jsoncpp
Parsing breaks because it is locale sensitive
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 8.9k
- Forks
- 2.7k
- Avg merge
- 31m
- Merged PRs (30d)
- 1
Description
I'm seeing this with version 1.6.5 on Ubuntu 16.04 (xenial).
Below is a trivial test program . (It requires the German locale to be installed.)
With the line that sets the locale commented out (assuming your are in a locale that uses '.' as the decimal point), everything works fine. With the locale setting enabled, the call fails and the error message is
'3.14' is not a number.
There is a related discussion in bug #283, but the issue below is different, I believe.
#include <jsoncpp/json/reader.h>
#include <iostream>
#include <locale>
int main(int, char **)
{
using namespace std;
locale::global(locale("de_DE.utf8"));
Json::Value root;
Json::CharReaderBuilder rbuilder;
rbuilder["collectComments"] = false;
string json_string = "3.14";
unique_ptr<Json::CharReader> reader(rbuilder.newCharReader());
auto begin = json_string.c_str();
auto end = json_string.c_str() + json_string.size();
string errors;
bool ok = reader->parse(begin, end, &root, &errors);
if (!ok)
{
cerr << errors << endl;
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided C++ test program, especially locale::global and Json::CharReaderBuilder::newCharReader(), then trace the parse call for the locale-sensitive number handling. Reproduce under the German locale and verify that the JSON string "3.14" parses successfully with the expected numeric value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100