forked from github/server
bug 2291: json settings must not override eressea.ini.
https://bugs.eressea.de/view.php?id=2291
This commit is contained in:
parent
7f03417c37
commit
912a8b5412
|
@ -797,18 +797,18 @@ static void json_settings(cJSON *json) {
|
|||
return;
|
||||
}
|
||||
for (child = json->child; child; child = child->next) {
|
||||
if (child->valuestring) {
|
||||
config_set(child->string, child->valuestring);
|
||||
}
|
||||
else {
|
||||
char value[32];
|
||||
if (child->type == cJSON_Number && child->valuedouble && child->valueint<child->valuedouble) {
|
||||
sprintf(value, "%f", child->valuedouble);
|
||||
if (config_get(child->string) == NULL) {
|
||||
if (child->valuestring) {
|
||||
config_set(child->string, child->valuestring);
|
||||
}
|
||||
else {
|
||||
sprintf(value, "%d", child->valueint);
|
||||
}
|
||||
if (config_get(child->string) == NULL) {
|
||||
char value[32];
|
||||
if (child->type == cJSON_Number && child->valuedouble && child->valueint < child->valuedouble) {
|
||||
sprintf(value, "%f", child->valuedouble);
|
||||
}
|
||||
else {
|
||||
sprintf(value, "%d", child->valueint);
|
||||
}
|
||||
config_set(child->string, value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,14 +70,17 @@ static void test_settings(CuTest * tc)
|
|||
"\"integer\" : 14,"
|
||||
"\"true\": true,"
|
||||
"\"game.id\": 4,"
|
||||
"\"game.name\": \"E3\","
|
||||
"\"false\": false,"
|
||||
"\"float\" : 1.5 }}";
|
||||
cJSON *json = cJSON_Parse(data);
|
||||
|
||||
test_cleanup();
|
||||
config_set("game.id", "42"); /* should not be replaced */
|
||||
config_set("game.name", "Eressea"); /* should not be replaced */
|
||||
json_config(json);
|
||||
CuAssertStrEquals(tc, "42", config_get("game.id"));
|
||||
CuAssertStrEquals(tc, "Eressea", config_get("game.name"));
|
||||
CuAssertStrEquals(tc, "1", config_get("true"));
|
||||
CuAssertStrEquals(tc, "0", config_get("false"));
|
||||
CuAssertStrEquals(tc, "1d4", config_get("string"));
|
||||
|
|
Loading…
Reference in New Issue