[gnome-software] Fix warning when refining an app with <content_rating> without type attribute
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Fix warning when refining an app with <content_rating> without type attribute
- Date: Thu, 24 Oct 2019 12:27:56 +0000 (UTC)
commit 6f4e2b802ce909cfde1467e97e7462734a10d605
Author: Andre Moreira Magalhaes <andre endlessm com>
Date: Mon Oct 14 20:02:34 2019 -0300
Fix warning when refining an app with <content_rating> without type attribute
It may happen that some apps have <content_rating> defined but without the
"type" attribute set (e.g. "com.sigmyne.crush").
This causes a warning when trying to compare the type with the known
supported values.
This patch fixes this issue by ignoring the content rating when type is
not set. It also avoids some unnecessary processing by changing the order
of the conditionals, by first checking whether the type is set/valid
before doing any other processing based on it.
plugins/core/gs-appstream.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
---
diff --git a/plugins/core/gs-appstream.c b/plugins/core/gs-appstream.c
index 74e865dd..3ccaaf41 100644
--- a/plugins/core/gs-appstream.c
+++ b/plugins/core/gs-appstream.c
@@ -601,9 +601,18 @@ gs_appstream_refine_app_content_rating (GsPlugin *plugin,
g_autoptr(AsContentRating) cr = as_content_rating_new ();
g_autoptr(GError) error_local = NULL;
g_autoptr(GPtrArray) content_attributes = NULL;
+ const gchar *content_rating_kind = NULL;
/* get kind */
- as_content_rating_set_kind (cr, xb_node_get_attr (content_rating, "type"));
+ content_rating_kind = xb_node_get_attr (content_rating, "type");
+ /* we only really expect/support OARS 1.0 and 1.1 */
+ if (content_rating_kind == NULL ||
+ (g_strcmp0 (content_rating_kind, "oars-1.0") != 0 &&
+ g_strcmp0 (content_rating_kind, "oars-1.1") != 0)) {
+ return TRUE;
+ }
+
+ as_content_rating_set_kind (cr, content_rating_kind);
/* get attributes; no attributes being found (i.e.
* `<content_rating type="*"/>`) is OK: it means that all attributes have
@@ -628,9 +637,7 @@ gs_appstream_refine_app_content_rating (GsPlugin *plugin,
as_content_rating_value_from_string (xb_node_get_text
(content_attribute)));
}
- /* we only really expect OARS 1.0 and 1.1 */
- if (g_str_has_prefix (as_content_rating_get_kind (cr), "oars-1."))
- gs_app_set_content_rating (app, cr);
+ gs_app_set_content_rating (app, cr);
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]