[glom] AppWindow::fill_menu_tables(): Escape table names before using as GioMenu action name.



commit 81098c767894a4e63f27d26414e868c9312d0157
Author: Murray Cumming <murrayc murrayc com>
Date:   Sun Mar 13 21:08:41 2016 +0100

    AppWindow::fill_menu_tables(): Escape table names before using as GioMenu action name.
    
    Because this causes a runtime error then crash, for instance if a
    table name contains spaces.
    This was probably broken in version 1.25.3 in September 2013 when
    converting the code from GtkMenu to GioMenu.
    Bug #763534 (m.rick.mac)

 glom/appwindow.cc |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)
---
diff --git a/glom/appwindow.cc b/glom/appwindow.cc
index 1a43d33..622eb36 100644
--- a/glom/appwindow.cc
+++ b/glom/appwindow.cc
@@ -1778,6 +1778,27 @@ void AppWindow::remove_developer_action(const Glib::RefPtr<Gio::SimpleAction>& r
 
 #endif // !GLOM_ENABLE_CLIENT_ONLY
 
+namespace
+{
+
+static Glib::ustring escape_for_action_name(const Glib::ustring& str)
+{
+  //TODO: This is incredibly inefficient:
+  //TODO: Check this with g_action_parse_detailed_name().
+  //See https://developer.gnome.org/gio/stable/GAction.html#g-action-parse-detailed-name
+  Glib::ustring result = str;
+  result = Utils::string_replace(result, "\n", "newline");
+  result = Utils::string_replace(result, " ", "space");
+  result = Utils::string_replace(result, "\t", "space");
+  result = Utils::string_replace(result, ":", "double-colon");
+  result = Utils::string_replace(result, "(", "open-parentheses");
+  result = Utils::string_replace(result, "(", "close-parentheses");
+
+  return result;
+}
+
+} //anonymous namespace
+
 void AppWindow::fill_menu_tables()
 {
   m_listNavTableActions.clear();
@@ -1819,7 +1840,7 @@ void AppWindow::fill_menu_tables()
     if(!table_info->get_hidden())
     {
       const auto title = Utils::string_escape_underscores(item_get_title_or_name(table_info));
-      const auto action_name = table_info->get_name();
+      const auto action_name = escape_for_action_name(table_info->get_name());
   
       menu->append(title, ACTION_GROUP_NAME_TABLES + "." + action_name);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]