diff --git a/lib/wp/conf.c b/lib/wp/conf.c index 0af23960..bdc130f0 100644 --- a/lib/wp/conf.c +++ b/lib/wp/conf.c @@ -251,34 +251,26 @@ open_and_load_sections (WpConf * self, const gchar *path, GError ** error) g_array_append_val (sections, section); } else { - /* if !is_object && !is_string, but we can't test it this way because - is_string expects quotes and we want to support strings without quotes */ - if (wp_spa_json_is_array (json) || - wp_spa_json_is_int (json) || - wp_spa_json_is_float (json) || - wp_spa_json_is_boolean (json) || - wp_spa_json_is_null (json)) - { - g_set_error (error, WP_DOMAIN_LIBRARY, WP_LIBRARY_ERROR_INVALID_ARGUMENT, - "invalid config file start (expected an object or a section name): %.*s", - (int) wp_spa_json_get_size (json), wp_spa_json_get_data (json)); - return FALSE; + g_auto (WpConfSection) section = { 0, }; + g_autoptr (WpSpaJson) tmp = NULL, toplevel = NULL; + g_autoptr (WpSpaJsonParser) parser = wp_spa_json_parser_new_undefined (json); + + /* get the very first token */ + tmp = wp_spa_json_parser_get_json (parser); + + /* if the top-level token is an object, parse that instead */ + if (tmp && wp_spa_json_is_object (tmp)) { + g_clear_pointer (&parser, wp_spa_json_parser_unref); + toplevel = g_steal_pointer (&tmp); + parser = wp_spa_json_parser_new_object (toplevel); + tmp = wp_spa_json_parser_get_json (parser); } - g_autoptr (WpSpaJsonParser) parser = wp_spa_json_is_object (json) ? - wp_spa_json_parser_new_object (json) : - wp_spa_json_parser_new_undefined (json); - while (TRUE) { - g_auto (WpConfSection) section = { 0, }; - g_autoptr (WpSpaJson) tmp = NULL; - - /* parse the section name */ - tmp = wp_spa_json_parser_get_json (parser); if (!tmp) break; - /* if !is_string, but we want to supprt strings without quotes */ + /* if !is_string, but we want to support strings without quotes */ if (wp_spa_json_is_container (tmp) || wp_spa_json_is_int (tmp) || wp_spa_json_is_float (tmp) || @@ -306,6 +298,9 @@ open_and_load_sections (WpConf * self, const gchar *path, GError ** error) section.location = g_strdup (path); g_array_append_val (sections, section); memset (§ion, 0, sizeof (section)); + + /* parse the next section name */ + tmp = wp_spa_json_parser_get_json (parser); } } diff --git a/tests/wp/conf/wireplumber.conf.d/empty.conf b/tests/wp/conf/wireplumber.conf.d/empty.conf new file mode 100644 index 00000000..e69de29b diff --git a/tests/wp/conf/wireplumber.conf.d/merge2.conf b/tests/wp/conf/wireplumber.conf.d/merge2.conf index b57c5414..d8fe2cae 100644 --- a/tests/wp/conf/wireplumber.conf.d/merge2.conf +++ b/tests/wp/conf/wireplumber.conf.d/merge2.conf @@ -1,3 +1,5 @@ +# some comment + { "override.wireplumber.section-override": { "key2": 5