summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Stebbins <[email protected]>2019-02-12 07:22:45 -0700
committerJohn Stebbins <[email protected]>2019-02-12 08:05:13 -0700
commitf7804e7ff4cd81986e09509e74e06e735c68408e (patch)
treea33ec2ed70663092a7ef761476279d278234876c
parent18077724c32912345d1a61528859f91be6341024 (diff)
LinGui: sanitize preset export filename
Removes illegal characters that may be in the preset name from the suggested filename and trims leading and trailing white space.
-rw-r--r--gtk/src/ghbcompat.h6
-rw-r--r--gtk/src/presets.c13
2 files changed, 16 insertions, 3 deletions
diff --git a/gtk/src/ghbcompat.h b/gtk/src/ghbcompat.h
index b4cf9deea..382125132 100644
--- a/gtk/src/ghbcompat.h
+++ b/gtk/src/ghbcompat.h
@@ -28,6 +28,12 @@
#include <gdk/gdk.h>
#include <string.h>
+#if defined(_WIN32)
+#define GHB_UNSAFE_FILENAME_CHARS "/:<>\"\\|?*"
+#else
+#define GHB_UNSAFE_FILENAME_CHARS "/"
+#endif
+
static inline void ghb_widget_get_preferred_width(
GtkWidget *widget, gint *min_width, gint * natural_width)
{
diff --git a/gtk/src/presets.c b/gtk/src/presets.c
index c88bb6b4f..9284b94f7 100644
--- a/gtk/src/presets.c
+++ b/gtk/src/presets.c
@@ -2026,17 +2026,18 @@ preset_export_action_cb(GSimpleAction *action, GVariant *param,
signal_user_data_t *ud)
{
hb_preset_index_t *path;
- const gchar *name;
GtkWindow *hb_window;
GtkWidget *dialog;
GtkResponseType response;
const gchar *exportDir;
gchar *filename;
GhbValue *dict;
+ char *preset_name;
path = get_selected_path(ud);
if (path == NULL || path->depth <= 0)
{
+ const gchar *name;
char * new_name;
free(path);
@@ -2056,7 +2057,7 @@ preset_export_action_cb(GSimpleAction *action, GVariant *param,
{
return;
}
- name = ghb_dict_get_string(dict, "PresetName");
+ preset_name = g_strdup(ghb_dict_get_string(dict, "PresetName"));
hb_window = GTK_WINDOW(GHB_WIDGET(ud->builder, "hb_window"));
dialog = gtk_file_chooser_dialog_new(_("Export Preset"), hb_window,
@@ -2070,10 +2071,16 @@ preset_export_action_cb(GSimpleAction *action, GVariant *param,
{
exportDir = ".";
}
- filename = g_strdup_printf("%s.json", name);
+
+ // Clean up preset name for use as a filename. Removing leading
+ // and trailing whitespace and filename illegal characters.
+ g_strstrip(preset_name);
+ g_strdelimit(preset_name, GHB_UNSAFE_FILENAME_CHARS, '_');
+ filename = g_strdup_printf("%s.json", preset_name);
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), exportDir);
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename);
g_free(filename);
+ g_free(preset_name);
response = gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_hide(dialog);