GNOME Bugzilla – Bug 385910
Suprising behaviour with duplicate groups in GKeyFile
Last modified: 2006-12-14 23:20:55 UTC
Please describe the problem: Where a group name is duplicated in a GKeyFile key-value pairs are added to the current active group. I consider this behaviour surprising. It should be fixed or documented. Steps to reproduce: See attached test case Actual results: Program outputs: ** Message: Group 'B' defines 'foo' as 'goo' Expected results: Program should output either: ** Message: Group 'B' defines 'foo' as 'baz' OR ** ERROR **: Parse error Does this happen every time? Yes Other information: A patch along the following lines would be my preferred solution: --- gkeyfile.c 2006-12-14 16:38:45.000000000 +0000 +++ newgkeyfile.c 2006-12-14 16:41:19.000000000 +0000 @@ -2887,8 +2887,12 @@ g_return_if_fail (key_file != NULL); g_return_if_fail (group_name != NULL); - if (g_key_file_lookup_group_node (key_file, group_name) != NULL) - return; + group = g_key_file_lookup_group_node (key_file, group_name); + if (group != NULL) + { + key_file->current_group = group; + return; + } group = g_new0 (GKeyFileGroup, 1); group->name = g_strdup (group_name);
Created attachment 78370 [details] The testcase referred to above
Created attachment 78373 [details] The test case described above (corrected)
2006-12-14 Matthias Clasen <mclasen@redhat.com> * glib/gkeyfile.c (g_key_file_add_group): If the group is already there, make it current. (#385910, Joe Halliwell) * tests/keyfile-test.c: Add a test for duplicate groups/keys.