diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ephy-file-helpers.c | 21 | ||||
-rw-r--r-- | lib/ephy-file-helpers.h | 1 |
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 |