From: Matthias Clasen Date: Thu, 14 Dec 2006 23:19:28 +0000 (+0000) Subject: If the group is already there, make it current. (#385910, Joe Halliwell) X-Git-Tag: GLIB_2_13_0~189 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=966872d78965178b8147279cd6cfabf49a89ccd4;p=platform%2Fupstream%2Fglib.git If the group is already there, make it current. (#385910, Joe Halliwell) 2006-12-14 Matthias Clasen * 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. --- diff --git a/ChangeLog b/ChangeLog index 2b292fdb6..572ec4f13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-12-14 Matthias Clasen + + * 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. + 2006-12-13 Matthias Clasen * m4macros/glib-gettext.m4: Require AC_CANONICAL_HOST in diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index d728ed2ce..397b1328f 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,8 @@ +2006-12-14 Matthias Clasen + + * glib/tmpl/keyfile.sgml: Clarify the behaviour + wrt. to duplicate keys and groups. + 2006-12-13 Matthias Clasen * glib/tmpl/modules.sgml: Point out that valid symbols may be NULL. diff --git a/docs/reference/glib/tmpl/keyfile.sgml b/docs/reference/glib/tmpl/keyfile.sgml index 6b1714e4b..950b6cfd0 100644 --- a/docs/reference/glib/tmpl/keyfile.sgml +++ b/docs/reference/glib/tmpl/keyfile.sgml @@ -92,6 +92,14 @@ Key and Group names are case-sensitive, for example a group called + +Note that in contrast to the +Desktop +Entry Specification, groups in key files may contain the same +key multiple times; the last entry wins. Key files may also contain +multiple groups with the same name; they are merged together. + + diff --git a/glib/gkeyfile.c b/glib/gkeyfile.c index 3ab7823e9..3542c2b9c 100644 --- a/glib/gkeyfile.c +++ b/glib/gkeyfile.c @@ -2887,8 +2887,12 @@ g_key_file_add_group (GKeyFile *key_file, 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 (key_file, group_name); + if (group != NULL) + { + key_file->current_group = group; + return; + } group = g_new0 (GKeyFileGroup, 1); group->name = g_strdup (group_name); diff --git a/tests/keyfile-test.c b/tests/keyfile-test.c index fc704bb24..77a2c53a5 100644 --- a/tests/keyfile-test.c +++ b/tests/keyfile-test.c @@ -1001,10 +1001,31 @@ test_duplicate_groups (void) "key2=123\n"; keyfile = load_data (data, 0); + check_string_value (keyfile, "Desktop Entry", "key1", "123"); + check_string_value (keyfile, "Desktop Entry", "key2", "123"); g_key_file_free (keyfile); } +/* http://bugzilla.gnome.org/show_bug.cgi?id=385910 */ +static void +test_duplicate_groups2 (void) +{ + GKeyFile *keyfile; + const gchar *data = + "[A]\n" + "foo=bar\n" + "[B]\n" + "foo=baz\n" + "[A]\n" + "foo=bang\n"; + + keyfile = load_data (data, 0); + check_string_value (keyfile, "A", "foo", "bang"); + check_string_value (keyfile, "B", "foo", "baz"); + + g_key_file_free (keyfile); +} int main (int argc, char *argv[]) @@ -1023,6 +1044,7 @@ main (int argc, char *argv[]) test_groups (); test_duplicate_keys (); test_duplicate_groups (); + test_duplicate_groups2 (); return 0; }