mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-10 04:45:48 +01:00
Merge branch 'backport-3555-keyfile-error-handling-glib-2-76' into 'glib-2-76'
Backport !3555 “gkeyfile: Fix overwriting of GError” to glib-2-76 See merge request GNOME/glib!3557
This commit is contained in:
commit
f72276d6a8
@ -4287,8 +4287,11 @@ g_key_file_parse_value_as_string (GKeyFile *key_file,
|
||||
GError **error)
|
||||
{
|
||||
gchar *string_value, *q0, *q;
|
||||
GSList *tmp_pieces = NULL;
|
||||
const gchar *p;
|
||||
|
||||
g_assert (pieces == NULL || *pieces == NULL);
|
||||
|
||||
string_value = g_new (gchar, strlen (value) + 1);
|
||||
|
||||
p = value;
|
||||
@ -4326,7 +4329,7 @@ g_key_file_parse_value_as_string (GKeyFile *key_file,
|
||||
G_KEY_FILE_ERROR_INVALID_VALUE,
|
||||
_("Key file contains escape character "
|
||||
"at end of line"));
|
||||
break;
|
||||
goto error;
|
||||
|
||||
default:
|
||||
if (pieces && *p == key_file->list_separator)
|
||||
@ -4348,6 +4351,7 @@ g_key_file_parse_value_as_string (GKeyFile *key_file,
|
||||
G_KEY_FILE_ERROR_INVALID_VALUE,
|
||||
_("Key file contains invalid escape "
|
||||
"sequence “%s”"), sequence);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -4358,7 +4362,7 @@ g_key_file_parse_value_as_string (GKeyFile *key_file,
|
||||
*q = *p;
|
||||
if (pieces && (*p == key_file->list_separator))
|
||||
{
|
||||
*pieces = g_slist_prepend (*pieces, g_strndup (q0, q - q0));
|
||||
tmp_pieces = g_slist_prepend (tmp_pieces, g_strndup (q0, q - q0));
|
||||
q0 = q + 1;
|
||||
}
|
||||
}
|
||||
@ -4374,11 +4378,17 @@ g_key_file_parse_value_as_string (GKeyFile *key_file,
|
||||
if (pieces)
|
||||
{
|
||||
if (q0 < q)
|
||||
*pieces = g_slist_prepend (*pieces, g_strndup (q0, q - q0));
|
||||
*pieces = g_slist_reverse (*pieces);
|
||||
tmp_pieces = g_slist_prepend (tmp_pieces, g_strndup (q0, q - q0));
|
||||
*pieces = g_slist_reverse (tmp_pieces);
|
||||
}
|
||||
|
||||
return string_value;
|
||||
|
||||
error:
|
||||
g_free (string_value);
|
||||
g_slist_free_full (tmp_pieces, g_free);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gchar *
|
||||
|
@ -544,7 +544,8 @@ test_string (void)
|
||||
"key6=trailing space \n"
|
||||
"[invalid]\n"
|
||||
"key1=\\a\\b\\0800xff\n"
|
||||
"key2=blabla\\\n";
|
||||
"key2=blabla\\\n"
|
||||
"key3=foo\\i\\\n";
|
||||
|
||||
keyfile = load_data (data, 0);
|
||||
|
||||
@ -563,6 +564,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", "key3", &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