mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-12 15:36:17 +01:00
gkeyfile: Temporarily re-allow invalid escapes when parsing strings
Before commit 71b7efd08a
, `GKeyFile`
incorrectly allowed invalid escape sequences: it would treat the
sequence as a literal, set a `GError`, but not return failure from the
function. So if a caller was explicitly checking for returned `GError`s,
they could detect the invalid escape; but if they were just checking the
function’s return value, they’d miss it.
This is not correct use of `GError`, and the [Desktop Entry
Spec](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s04.html)
doesn’t allow for invalid escape sequences to be accepted. So it’s wrong
in both ways.
However, the commit above changed this behaviour without realising it,
quite close to the 2.78 stable release deadline. There are numerous key
files in the wild which use invalid escape sequences, and it’s too late
in the cycle to ‘break’ parsing of all of them.
So, for now, revert to the old behaviour for invalid escape sequences,
and give people another cycle to adapt to the changes. This will likely
mean they end up calling `g_key_file_get_value()` rather than
`g_key_file_get_string()`. See
https://gitlab.gnome.org/GNOME/glib/-/issues/3098 for tracking
re-enabling the error handling for invalid escape sequences.
Signed-off-by: Philip Withnall <philip@tecnocode.co.uk>
Fixes: #3095
See: #3098
This commit is contained in:
parent
efc74ca36c
commit
4a96727642
@ -4351,6 +4351,7 @@ g_key_file_parse_value_as_string (GKeyFile *key_file,
|
||||
break;
|
||||
|
||||
case '\0':
|
||||
g_clear_error (error);
|
||||
g_set_error_literal (error, G_KEY_FILE_ERROR,
|
||||
G_KEY_FILE_ERROR_INVALID_VALUE,
|
||||
_("Key file contains escape character "
|
||||
@ -4373,11 +4374,25 @@ g_key_file_parse_value_as_string (GKeyFile *key_file,
|
||||
sequence[1] = *p;
|
||||
sequence[2] = '\0';
|
||||
|
||||
/* FIXME: This should be a fatal error, but there was a
|
||||
* bug which prevented that being reported for a long
|
||||
* time, so a lot of applications and in-the-field key
|
||||
* files use invalid escape sequences without anticipating
|
||||
* problems. For now (GLib 2.78), message about it; in
|
||||
* future, the behaviour may become fatal again.
|
||||
*
|
||||
* The previous behaviour was to set the #GError but not
|
||||
* return failure from the function, so the caller could
|
||||
* explicitly check for invalid escapes, but also ignore
|
||||
* the error if they want. This is not how #GError is
|
||||
* meant to be used, but the #GKeyFile code is very old.
|
||||
*
|
||||
* See https://gitlab.gnome.org/GNOME/glib/-/issues/3098 */
|
||||
g_clear_error (error);
|
||||
g_set_error (error, G_KEY_FILE_ERROR,
|
||||
G_KEY_FILE_ERROR_INVALID_VALUE,
|
||||
_("Key file contains invalid escape "
|
||||
"sequence “%s”"), sequence);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user