GKeyFile: Inconsistent behavior of comment writing above a group
GLib version: 2.74.6
Writing a comment at the beginning of a file, i.e. implicitly above the first group, adds a line break after the comment as soon as it is written.
i.e. running
g_key_file_load_from_file (key_file, path, G_KEY_FILE_KEEP_COMMENTS, NULL);
g_key_file_set_comment (key_file, NULL, NULL, "test", NULL);
g_key_file_save_to_file (key_file, path, NULL);
on this file
[Test]
test=1
gives
#test
[Test]
test=1
On the other hand, writing a comment above a given group, including explicitly above the first group, does not add a line break after the comment on first write, but then adds it on next load/save if comments are kept.
i.e. running
g_key_file_load_from_file (key_file, path, G_KEY_FILE_KEEP_COMMENTS, NULL);
g_key_file_set_comment (key_file, "Test", NULL, "test", NULL);
g_key_file_save_to_file (key_file, path, NULL);
on the above file gives
#test
[Test]
test=1
but running
g_key_file_load_from_file (key_file, path, G_KEY_FILE_KEEP_COMMENTS, NULL);
g_key_file_save_to_file (key_file, path, NULL);
on the above result gives
#test
[Test]
test=1
This is in itself a minor problem, but it complicates for example the comparison between a file comment and a reference comment: the first comparison succeeds and the second fails, or the other way around.
Also, it may be related to #104 (closed), because removing a comment at the beginning of a file works fine, but removing a comment above a given group does not.