summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhuyaliang <[email protected]>2023-12-16 21:35:28 +0800
committerraveit65 <[email protected]>2024-02-01 00:00:33 +0100
commit3dc5ae8a54eec467c89bf1619bf15493a6f7957c (patch)
tree66f4e7792b1d7781b9a2fd9d612b76640ca05e99
parent8a32bf9f8e192d8b0aab3a9459b59658d5aa5adf (diff)
downloadengrampa-3dc5ae8a54eec467c89bf1619bf15493a6f7957c.tar.bz2
engrampa-3dc5ae8a54eec467c89bf1619bf15493a6f7957c.tar.xz
Escapes a string for use in a URI. replace special "# and ?" characters in uri
Fix https://github.com/mate-desktop/engrampa/issues/501
-rw-r--r--src/file-utils.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/file-utils.c b/src/file-utils.c
index 6d4f328..249512d 100644
--- a/src/file-utils.c
+++ b/src/file-utils.c
@@ -148,6 +148,7 @@ get_dir_content_if_unique (const char *uri)
while ((info = g_file_enumerator_next_file (file_enum, NULL, &err)) != NULL) {
const char *name;
+ char *new_name;
if (err != NULL) {
g_warning ("Failed to get info while enumerating children: %s", err->message);
@@ -169,8 +170,10 @@ get_dir_content_if_unique (const char *uri)
break;
}
- content_uri = build_uri (uri, name, NULL);
+ new_name = g_uri_escape_string (name, NULL, TRUE);
+ content_uri = build_uri (uri, new_name, NULL);
g_object_unref (info);
+ g_free (new_name);
}
if (err != NULL) {
@@ -1043,16 +1046,19 @@ get_alternative_uri (const char *folder,
{
char *new_uri = NULL;
int n = 1;
+ char *new_name;
+ new_name = g_uri_escape_string (name, NULL, TRUE);
do {
g_free (new_uri);
if (n == 1)
- new_uri = g_strconcat (folder, "/", name, NULL);
+ new_uri = g_strconcat (folder, "/", new_name, NULL);
else
- new_uri = g_strdup_printf ("%s/%s%%20(%d)", folder, name, n);
+ new_uri = g_strdup_printf ("%s/%s%%20(%d)", folder, new_name, n);
n++;
} while (uri_exists (new_uri));
+ g_free (new_name);
return new_uri;
}