After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 385910 - Suprising behaviour with duplicate groups in GKeyFile
Suprising behaviour with duplicate groups in GKeyFile
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
2.12.x
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2006-12-14 16:43 UTC by Joe Halliwell
Modified: 2006-12-14 23:20 UTC
See Also:
GNOME target: ---
GNOME version: 2.17/2.18


Attachments
The testcase referred to above (826 bytes, text/x-csrc)
2006-12-14 16:43 UTC, Joe Halliwell
Details
The test case described above (corrected) (827 bytes, text/x-csrc)
2006-12-14 16:53 UTC, Joe Halliwell
Details

Description Joe Halliwell 2006-12-14 16:43:04 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);
Comment 1 Joe Halliwell 2006-12-14 16:43:47 UTC
Created attachment 78370 [details]
The testcase referred to above
Comment 2 Joe Halliwell 2006-12-14 16:53:28 UTC
Created attachment 78373 [details]
The test case described above (corrected)
Comment 3 Matthias Clasen 2006-12-14 23:20:55 UTC
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.