mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-26 04:02:09 +01:00
Merge branch '3098-keyfile-escaping' into 'main'
Revert "gkeyfile: Temporarily re-allow invalid escapes when parsing strings" Closes #3098 See merge request GNOME/glib!3618
This commit is contained in:
commit
240156d174
@ -4351,7 +4351,6 @@ 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 "
|
||||
@ -4374,25 +4373,11 @@ 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;
|
||||
|
@ -589,8 +589,9 @@ test_string (void)
|
||||
"key6=trailing space \n"
|
||||
"[invalid]\n"
|
||||
"key1=\\a\\b\\0800xff\n"
|
||||
"key2=blabla\\\n"
|
||||
"key3=foo\\i\\\n";
|
||||
"key2=blabla\\\n" /* escape at end of line */
|
||||
"key3=\\ifoo\n" /* invalid escape */
|
||||
"key4=\\i\\hfoo\n"; /* invalid escape with multiple stacked errors */
|
||||
|
||||
keyfile = load_data (data, 0);
|
||||
|
||||
@ -613,6 +614,10 @@ test_string (void)
|
||||
check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE);
|
||||
g_free (value);
|
||||
|
||||
value = g_key_file_get_string (keyfile, "invalid", "key4", &error);
|
||||
check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE);
|
||||
g_free (value);
|
||||
|
||||
g_key_file_set_string (keyfile, "inserted", "key1", "simple");
|
||||
g_key_file_set_string (keyfile, "inserted", "key2", " leading space");
|
||||
g_key_file_set_string (keyfile, "inserted", "key3", "\tleading tab");
|
||||
|
Loading…
x
Reference in New Issue
Block a user