aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2012-09-10 19:06:38 +0800
committerCarlos Garcia Campos <carlosgc@gnome.org>2012-09-10 23:04:04 +0800
commit6e6df39c03355307484b81c73a6812eb1ba28bc7 (patch)
treebc81f9595698081f30af335febe694bbc8b2d11c /lib
parent91b17b84738f666579fbfd7aa722680b9a90a1d6 (diff)
downloadgsoc2013-epiphany-6e6df39c03355307484b81c73a6812eb1ba28bc7.tar
gsoc2013-epiphany-6e6df39c03355307484b81c73a6812eb1ba28bc7.tar.gz
gsoc2013-epiphany-6e6df39c03355307484b81c73a6812eb1ba28bc7.tar.bz2
gsoc2013-epiphany-6e6df39c03355307484b81c73a6812eb1ba28bc7.tar.lz
gsoc2013-epiphany-6e6df39c03355307484b81c73a6812eb1ba28bc7.tar.xz
gsoc2013-epiphany-6e6df39c03355307484b81c73a6812eb1ba28bc7.tar.zst
gsoc2013-epiphany-6e6df39c03355307484b81c73a6812eb1ba28bc7.zip
ephy-file-helpers: Add ephy_sanitize_filename()
To convert any possible directory separator into an underscore. https://bugzilla.gnome.org/show_bug.cgi?id=683711
Diffstat (limited to 'lib')
-rw-r--r--lib/ephy-file-helpers.c21
-rw-r--r--lib/ephy-file-helpers.h1
2 files changed, 22 insertions, 0 deletions
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