Commit 73ac9eeb authored by Alexandru Pandelea's avatar Alexandru Pandelea

batch-rename-utilities: escape strings in the sparql query

The sparql query will fail if the file name or the parent uri have a
character that needs escaping. An example would be the character '

To fix this, escape the file name and the parent uri in the query.

https://bugzilla.gnome.org/show_bug.cgi?id=770944
parent 8e1df7a8
......@@ -1034,6 +1034,8 @@ check_metadata_for_selection (NautilusBatchRenameDialog *dialog,
GList *selection_metadata;
guint i;
g_autofree gchar *parent_uri = NULL;
g_autofree gchar *parent_uri_escaped = NULL;
gchar *file_name_escaped;
error = NULL;
selection_metadata = NULL;
......@@ -1057,33 +1059,35 @@ check_metadata_for_selection (NautilusBatchRenameDialog *dialog,
"WHERE { ?file a nfo:FileDataObject. ");
parent_uri = nautilus_file_get_parent_uri (NAUTILUS_FILE (selection->data));
parent_uri_escaped = g_markup_escape_text (parent_uri, -1);
g_string_append_printf (query,
"FILTER(tracker:uri-is-parent('%s', nie:url(?file))) ",
parent_uri);
parent_uri_escaped);
for (l = selection; l != NULL; l = l->next)
{
file = NAUTILUS_FILE (l->data);
file_name = nautilus_file_get_name (file);
file_name_escaped = g_markup_escape_text (file_name, -1);
if (l == selection)
{
g_string_append_printf (query,
"FILTER (nfo:fileName(?file) IN ('%s', ",
file_name);
file_name_escaped);
}
else if (l->next == NULL)
{
g_string_append_printf (query,
"'%s')) ",
file_name);
file_name_escaped);
}
else
{
g_string_append_printf (query,
"'%s', ",
file_name);
file_name_escaped);
}
file_metadata = g_new0 (FileMetadata, 1);
......@@ -1093,6 +1097,7 @@ check_metadata_for_selection (NautilusBatchRenameDialog *dialog,
selection_metadata = g_list_prepend (selection_metadata, file_metadata);
g_free (file_name);
g_free (file_name_escaped);
}
selection_metadata = g_list_reverse (selection_metadata);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment