open-source-parsers/jsoncpp

Parsing breaks because it is locale sensitive

Open

#439 geöffnet am 9. März 2016

Auf GitHub ansehen
 (7 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)C++ (2.602 Forks)batch import
bughelp wanted

Repository-Metriken

Stars
 (7.542 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 18h 26m) (10 gemergte PRs in 30 T)

Beschreibung

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