bug 2291: json settings must not override eressea.ini.

https://bugs.eressea.de/view.php?id=2291
This commit is contained in:
Enno Rehling 2017-03-01 21:17:37 +01:00
parent 7f03417c37
commit 912a8b5412
2 changed files with 13 additions and 10 deletions

View File

@ -797,18 +797,18 @@ static void json_settings(cJSON *json) {
return; return;
} }
for (child = json->child; child; child = child->next) { for (child = json->child; child; child = child->next) {
if (child->valuestring) { if (config_get(child->string) == NULL) {
config_set(child->string, child->valuestring); 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);
} }
else { else {
sprintf(value, "%d", child->valueint); char value[32];
} if (child->type == cJSON_Number && child->valuedouble && child->valueint < child->valuedouble) {
if (config_get(child->string) == NULL) { sprintf(value, "%f", child->valuedouble);
}
else {
sprintf(value, "%d", child->valueint);
}
config_set(child->string, value); config_set(child->string, value);
} }
} }

View File

@ -70,14 +70,17 @@ static void test_settings(CuTest * tc)
"\"integer\" : 14," "\"integer\" : 14,"
"\"true\": true," "\"true\": true,"
"\"game.id\": 4," "\"game.id\": 4,"
"\"game.name\": \"E3\","
"\"false\": false," "\"false\": false,"
"\"float\" : 1.5 }}"; "\"float\" : 1.5 }}";
cJSON *json = cJSON_Parse(data); cJSON *json = cJSON_Parse(data);
test_cleanup(); test_cleanup();
config_set("game.id", "42"); /* should not be replaced */ config_set("game.id", "42"); /* should not be replaced */
config_set("game.name", "Eressea"); /* should not be replaced */
json_config(json); json_config(json);
CuAssertStrEquals(tc, "42", config_get("game.id")); CuAssertStrEquals(tc, "42", config_get("game.id"));
CuAssertStrEquals(tc, "Eressea", config_get("game.name"));
CuAssertStrEquals(tc, "1", config_get("true")); CuAssertStrEquals(tc, "1", config_get("true"));
CuAssertStrEquals(tc, "0", config_get("false")); CuAssertStrEquals(tc, "0", config_get("false"));
CuAssertStrEquals(tc, "1d4", config_get("string")); CuAssertStrEquals(tc, "1d4", config_get("string"));