diff --git a/ChangeLog b/ChangeLog index ec3256f91..f047781e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-04-18 Matthias Clasen + + * glib/gkeyfile.c (g_key_file_add_group): Accept duplicate + groups. (#157877, Sebastien Bacher) + + * tests/keyfile-test.c: Add tests for duplicate key and + duplicate group handling. + 2006-04-17 Matthias Clasen * glib/gcompletion.c (g_completion_complete_utf8): Make passing diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index ec3256f91..f047781e7 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,11 @@ +2006-04-18 Matthias Clasen + + * glib/gkeyfile.c (g_key_file_add_group): Accept duplicate + groups. (#157877, Sebastien Bacher) + + * tests/keyfile-test.c: Add tests for duplicate key and + duplicate group handling. + 2006-04-17 Matthias Clasen * glib/gcompletion.c (g_completion_complete_utf8): Make passing diff --git a/glib/gkeyfile.c b/glib/gkeyfile.c index 08c171553..eeb8ee12d 100644 --- a/glib/gkeyfile.c +++ b/glib/gkeyfile.c @@ -2660,7 +2660,9 @@ g_key_file_add_group (GKeyFile *key_file, g_return_if_fail (key_file != NULL); g_return_if_fail (group_name != NULL); - g_return_if_fail (g_key_file_lookup_group_node (key_file, group_name) == NULL); + + if (g_key_file_lookup_group_node (key_file, group_name) != NULL) + 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 ee3d9fb4e..7680881cc 100644 --- a/tests/keyfile-test.c +++ b/tests/keyfile-test.c @@ -880,6 +880,37 @@ test_groups (void) g_key_file_free (keyfile); } +static void +test_duplicate_keys (void) +{ + GKeyFile *keyfile; + const gchar *data = + "[1]\n" + "key1=123\n" + "key1=345\n"; + + keyfile = load_data (data, 0); + check_string_value (keyfile, "1", "key1", "345"); + + g_key_file_free (keyfile); +} + +/* http://bugzilla.gnome.org/show_bug.cgi?id=157877 */ +static void +test_duplicate_groups (void) +{ + GKeyFile *keyfile; + const gchar *data = + "[Desktop Entry]\n" + "key1=123\n" + "[Desktop Entry]\n" + "key2=123\n"; + + keyfile = load_data (data, 0); + + g_key_file_free (keyfile); +} + int main (int argc, char *argv[]) @@ -896,6 +927,8 @@ main (int argc, char *argv[]) test_group_remove (); test_key_remove (); test_groups (); + test_duplicate_keys (); + test_duplicate_groups (); return 0; }