Details
[Home]
Issue of the Implementation # D0027
Brief
Invocation of the interface "g_key_file_remove_comment" does not remove comment in specific case
Detailed Description
Invocation of the interface g_key_file_remove_comment with parameters group_name = "some_group", key = "NULL" does not remove comment above the group. This is caused by duality of the comment structure. In implementation of the "g_key_file_set_comment" interface used "comment" field of the structure, but when loading from file or data then the parsing used "NULL" key in the map.
Problem location(s) in the standard
Linux Standard Base Desktop Specification 3.1, Chapter 12. Libraries, 12.2 Interfaces for libglib-2.0; http://www.gtk.org/api/2.6/glib/glib-Key-value-file-parser.html#g-key-file-remove-comment
Reproducing
- Load a key file from data.
- Call g_key_file_remove_comment with group "group_name" = "Second Group"(existing group in the key file), "key" = NULL. The correct behaviour is to remove the comment above the "Second Group" group, which contains "Third Comment" text.
- Call g_key_file_get_comment with same parameters. If the comment is removed by the previous call the g_key_file_get_comment returns NULL. Otherwise the g_key_file_get_comment returns a text of the comment that demonstrates incorrect behaviour of the g_key_file_remove_comment.
Example
#include <string.h> #include <stdio.h> #include <glib.h> char *textComment="#First Comment\n[First Group]\nWelcome=Hello\nWelcome[en]="\ "Hello\n \n#Second Comment\nFirst=1\n#Third Comment\n[Second Group]\n"\ "#Fourth Comment\nSecond=2\nWelcome=Hello\nWelcome[en]=Hi\n" "Welcome[fr]=Bonjourn\n"; #define GROUP "Second Group" #define KEY NULL int main () { GKeyFile *gkf=NULL; gchar *cmnt=NULL; gkf=g_key_file_new(); g_key_file_load_from_data(gkf, textComment, strlen(textComment), G_KEY_FILE_KEEP_COMMENTS, NULL); g_key_file_remove_comment(gkf, GROUP, KEY, NULL); cmnt=g_key_file_get_comment(gkf, GROUP, KEY, NULL); if (cmnt==NULL) printf ("CORRECT: comment removed\n"); else printf ("INCORRECT: comment = \"%s\" end of comment\n", cmnt); return 0; }
Component
gtk-glib 2.6.2 or later
Accepted
Gnome Bugzilla 476852
[Home]