[glib: 18/24] GDesktopAppInfo: Ensure that URI scheme is a valid argument




commit 6fef60b65c8a10ba29b70fe4b94ae5d9c3dcacfb
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Tue Jun 14 16:30:42 2022 +0200

    GDesktopAppInfo: Ensure that URI scheme is a valid argument

 gio/gdesktopappinfo.c        |  2 ++
 gio/tests/desktop-app-info.c | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+)
---
diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c
index da59da3fd7..8845d6b660 100644
--- a/gio/gdesktopappinfo.c
+++ b/gio/gdesktopappinfo.c
@@ -4626,6 +4626,8 @@ g_app_info_get_default_for_uri_scheme (const char *uri_scheme)
   GAppInfo *app_info;
   char *content_type, *scheme_down;
 
+  g_return_val_if_fail (uri_scheme != NULL && *uri_scheme != '\0', NULL);
+
   scheme_down = g_ascii_strdown (uri_scheme, -1);
   content_type = g_strdup_printf ("x-scheme-handler/%s", scheme_down);
   g_free (scheme_down);
diff --git a/gio/tests/desktop-app-info.c b/gio/tests/desktop-app-info.c
index 75bf6c557f..6d0f8974e1 100644
--- a/gio/tests/desktop-app-info.c
+++ b/gio/tests/desktop-app-info.c
@@ -119,6 +119,23 @@ test_default (void)
   g_assert_cmpstr (g_app_info_get_id (info), ==, g_app_info_get_id (info2));
   g_object_unref (info);
 
+  g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                         "*assertion*uri_scheme*failed*");
+  g_assert_null (g_app_info_get_default_for_uri_scheme (NULL));
+  g_test_assert_expected_messages ();
+
+  g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
+                         "*assertion*uri_scheme*failed*");
+  g_assert_null (g_app_info_get_default_for_uri_scheme (""));
+  g_test_assert_expected_messages ();
+
+  g_app_info_set_as_default_for_type (info3, "x-scheme-handler/glib", &error);
+  g_assert_no_error (error);
+  info = g_app_info_get_default_for_uri_scheme ("glib");
+  g_assert_nonnull (info);
+  g_assert_true (g_app_info_equal (info, info3));
+  g_object_unref (info);
+
   /* now try adding something, but not setting as default */
   g_app_info_add_supports_type (info3, "application/x-test", &error);
   g_assert_no_error (error);
@@ -141,10 +158,14 @@ test_default (void)
 
   /* now clean it all up */
   g_app_info_reset_type_associations ("application/x-test");
+  g_app_info_reset_type_associations ("x-scheme-handler/glib");
 
   list = g_app_info_get_all_for_type ("application/x-test");
   g_assert_null (list);
 
+  list = g_app_info_get_all_for_type ("x-scheme-handler/glib");
+  g_assert_null (list);
+
   g_app_info_delete (info1);
   g_app_info_delete (info2);
   g_app_info_delete (info3);


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