From 912a8b5412d7fd213ab29e226c060ddbcb8c7b17 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 1 Mar 2017 21:17:37 +0100 Subject: [PATCH] bug 2291: json settings must not override eressea.ini. https://bugs.eressea.de/view.php?id=2291 --- src/kernel/jsonconf.c | 20 ++++++++++---------- src/kernel/jsonconf.test.c | 3 +++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index 287aa61db..0f5642c42 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -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->valueintvaluedouble) { - 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); } } diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index 8b8ac8c14..456a27d22 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -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"));