diff options
author | Richard Hughes <richard@hughsie.com> | 2021-04-15 09:01:01 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2021-04-15 09:57:51 +0100 |
commit | 44e20bd2e921464185fd12a1ea43b691779a127b (patch) | |
tree | 05aee4f6d39c28196c396aadbb5e293e712a2822 | |
parent | c795c69c3cbf695e94408765f9bace45bb5f2b85 (diff) | |
download | appstream-glib-44e20bd2e921464185fd12a1ea43b691779a127b.tar.gz |
Do not show a critical warning on <suggests><id/></suggests>
Fixes https://github.com/hughsie/appstream-glib/issues/396
-rw-r--r-- | libappstream-glib/as-self-test.c | 21 | ||||
-rw-r--r-- | libappstream-glib/as-suggest.c | 4 |
2 files changed, 24 insertions, 1 deletions
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c index 78af947..29fc20a 100644 --- a/libappstream-glib/as-self-test.c +++ b/libappstream-glib/as-self-test.c @@ -4190,6 +4190,26 @@ as_test_store_versions_func (void) } static void +as_test_store_invalid_func (void) +{ + gboolean ret; + g_autoptr(AsStore) store; + g_autoptr(GError) error = NULL; + + /* load a file to the store */ + store = as_store_new (); + ret = as_store_from_xml (store, + "<components version=\"0.6\">" + "<component type=\"desktop\">" + "<id>test.desktop</id>" + "<suggests><id/></suggests>" + "</component>" + "</components>", NULL, &error); + g_assert_no_error (error); + g_assert_true (ret); +} + +static void as_test_store_addons_func (void) { AsApp *app; @@ -5851,6 +5871,7 @@ main (int argc, char **argv) g_test_add_func ("/AppStream/store{merges}", as_test_store_merges_func); g_test_add_func ("/AppStream/store{merges-local}", as_test_store_merges_local_func); g_test_add_func ("/AppStream/store{addons}", as_test_store_addons_func); + g_test_add_func ("/AppStream/store{invalid}", as_test_store_invalid_func); g_test_add_func ("/AppStream/store{versions}", as_test_store_versions_func); g_test_add_func ("/AppStream/store{origin}", as_test_store_origin_func); g_test_add_func ("/AppStream/store{yaml}", as_test_store_yaml_func); diff --git a/libappstream-glib/as-suggest.c b/libappstream-glib/as-suggest.c index d9f90ac..707f3a0 100644 --- a/libappstream-glib/as-suggest.c +++ b/libappstream-glib/as-suggest.c @@ -168,6 +168,7 @@ as_suggest_add_id (AsSuggest *suggest, const gchar *id) { AsSuggestPrivate *priv = GET_PRIVATE (suggest); g_return_if_fail (AS_IS_SUGGEST (suggest)); + g_return_if_fail (id != NULL); g_ptr_array_add (priv->ids, as_ref_string_new (id)); } @@ -233,7 +234,8 @@ as_suggest_node_parse (AsSuggest *suggest, GNode *node, if (tmp != NULL) as_suggest_set_kind (suggest, as_suggest_kind_from_string (tmp)); for (c = node->children; c != NULL; c = c->next) { - if (as_node_get_tag (c) == AS_TAG_ID) + if (as_node_get_tag (c) == AS_TAG_ID && + as_node_get_data (c) != NULL) as_suggest_add_id (suggest, as_node_get_data (c)); } return TRUE; |