mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 23:16:14 +01:00
Merge branch 'keyfile-escape-fix' into 'main'
gkeyfile: Fix overwriting of GError See merge request GNOME/glib!3555
This commit is contained in:
commit
ff0eea48ae
@ -4313,8 +4313,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;
|
||||
@ -4352,7 +4355,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)
|
||||
@ -4374,20 +4377,21 @@ 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;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*q = *p;
|
||||
if (pieces && (*p == key_file->list_separator))
|
||||
{
|
||||
*pieces = g_slist_prepend (*pieces, g_strndup (q0, q - q0));
|
||||
q0 = q + 1;
|
||||
}
|
||||
}
|
||||
{
|
||||
*q = *p;
|
||||
if (pieces && (*p == key_file->list_separator))
|
||||
{
|
||||
tmp_pieces = g_slist_prepend (tmp_pieces, g_strndup (q0, q - q0));
|
||||
q0 = q + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (*p == '\0')
|
||||
break;
|
||||
@ -4398,13 +4402,19 @@ g_key_file_parse_value_as_string (GKeyFile *key_file,
|
||||
|
||||
*q = '\0';
|
||||
if (pieces)
|
||||
{
|
||||
if (q0 < q)
|
||||
*pieces = g_slist_prepend (*pieces, g_strndup (q0, q - q0));
|
||||
*pieces = g_slist_reverse (*pieces);
|
||||
}
|
||||
{
|
||||
if (q0 < q)
|
||||
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 *
|
||||
|
@ -580,16 +580,17 @@ test_string (void)
|
||||
"3",
|
||||
};
|
||||
const gchar *data =
|
||||
"[valid]\n"
|
||||
"key1=\\s\\n\\t\\r\\\\\n"
|
||||
"key2=\"quoted\"\n"
|
||||
"key3='quoted'\n"
|
||||
"key4=\xe2\x89\xa0\xe2\x89\xa0\n"
|
||||
"key5= leading space\n"
|
||||
"key6=trailing space \n"
|
||||
"[invalid]\n"
|
||||
"key1=\\a\\b\\0800xff\n"
|
||||
"key2=blabla\\\n";
|
||||
"[valid]\n"
|
||||
"key1=\\s\\n\\t\\r\\\\\n"
|
||||
"key2=\"quoted\"\n"
|
||||
"key3='quoted'\n"
|
||||
"key4=\xe2\x89\xa0\xe2\x89\xa0\n"
|
||||
"key5= leading space\n"
|
||||
"key6=trailing space \n"
|
||||
"[invalid]\n"
|
||||
"key1=\\a\\b\\0800xff\n"
|
||||
"key2=blabla\\\n"
|
||||
"key3=foo\\i\\\n";
|
||||
|
||||
keyfile = load_data (data, 0);
|
||||
|
||||
@ -608,6 +609,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…
Reference in New Issue
Block a user