[epiphany] ephy-file-helpers: Add ephy_sanitize_filename()
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] ephy-file-helpers: Add ephy_sanitize_filename()
- Date: Mon, 10 Sep 2012 15:05:44 +0000 (UTC)
commit 6e6df39c03355307484b81c73a6812eb1ba28bc7
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Mon Sep 10 13:06:38 2012 +0200
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
doc/reference/epiphany-sections.txt | 1 +
lib/ephy-file-helpers.c | 21 +++++++++++++++++++++
lib/ephy-file-helpers.h | 1 +
3 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/doc/reference/epiphany-sections.txt b/doc/reference/epiphany-sections.txt
index cbac79f..ae89084 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 f8e2560..680f2b5 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 f7564b5..fc50c63 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]