aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/reference/epiphany-sections.txt1
-rw-r--r--lib/ephy-file-helpers.c21
-rw-r--r--lib/ephy-file-helpers.h1
3 files changed, 23 insertions, 0 deletions
diff --git a/doc/reference/epiphany-sections.txt b/doc/reference/epiphany-sections.txt
index cbac79f04..ae89084fa 100644
--- a/doc/reference/epiphany-sections.txt
+++ b/doc/reference/epiphany-sections.txt
@@ -185,6 +185,7 @@ ephy_file_switch_temp_file
ephy_file_tmp_dir
ephy_file_tmp_filename
ephy_file_create_data_uri_for_filename
+ephy_sanitize_filename
</SECTION>
<SECTION>
diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c
index f8e25606a..680f2b5ed 100644
--- a/lib/ephy-file-helpers.c
+++ b/lib/ephy-file-helpers.c
@@ -1050,3 +1050,24 @@ ephy_file_create_data_uri_for_filename (const char *filename,
return uri;
}
+
+/**
+ * ephy_sanitize_filename:
+ * @filename: a filename
+ *
+ * Sanitize @filename to make sure it's a valid filename. If the
+ * filename contains directory separators, they will be converted to
+ * underscores, so that they are not interpreted as a path by the
+ * filesystem.
+ *
+ * Note that it modifies string in place. The return value is to allow nesting.
+ *
+ * Returns: the sanitized filename
+ */
+char *
+ephy_sanitize_filename (char *filename)
+{
+ g_return_val_if_fail (filename != NULL, NULL);
+
+ return g_strdelimit (filename, G_DIR_SEPARATOR_S, '_');
+}
diff --git a/lib/ephy-file-helpers.h b/lib/ephy-file-helpers.h
index f7564b55b..fc50c638d 100644
--- a/lib/ephy-file-helpers.h
+++ b/lib/ephy-file-helpers.h
@@ -91,6 +91,7 @@ gboolean ephy_file_delete_dir_recursively (GFile *file,
void ephy_file_delete_uri (const char *uri);
char * ephy_file_create_data_uri_for_filename (const char *filename,
const char *mime_type);
+char * ephy_sanitize_filename (char *filename);
G_END_DECLS