[gnome-software] malcontent: Correctly distinguish empty content ratings from missing ones



commit cded66b45e505613a5faee254e688e5882e15272
Author: Philip Withnall <withnall endlessm com>
Date:   Wed Oct 2 15:36:00 2019 +0100

    malcontent: Correctly distinguish empty content ratings from missing ones
    
    As with the previous commit to make this change to the `appstream`
    plugin, the OARS semantics require that if `<content_rating/>` is
    present, any attributes whcih are missing from it (which could be ‘all
    attributes’) are assumed to have a value of `none`. If
    `<content_rating/>` is missing, they are assumed to have a value of
    `unknown`.
    
    Handle that correctly, and correctly convert all `unknown` values to
    `intense` before comparing them against the user’s policy.
    
    See the [OARS
    specification](https://github.com/hughsie/oars/blob/master/specification/oars-1.1.md).
    
    Signed-off-by: Philip Withnall <withnall endlessm com>

 plugins/malcontent/gs-plugin-malcontent.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/plugins/malcontent/gs-plugin-malcontent.c b/plugins/malcontent/gs-plugin-malcontent.c
index 68d08544..e588553e 100644
--- a/plugins/malcontent/gs-plugin-malcontent.c
+++ b/plugins/malcontent/gs-plugin-malcontent.c
@@ -91,12 +91,16 @@ app_is_expected_to_have_content_rating (GsApp *app)
  * this user to use), return %TRUE; otherwise return %FALSE.
  *
  * The #AsContentRating in @app may be %NULL if no OARS ratings are provided for
- * the app. If so, we have to assume the most restrictive ratings. */
+ * the app. If so, we have to assume the most restrictive ratings. However, if
+ * @rating is provided but is empty, we assume that every section in it has
+ * value %AS_CONTENT_RATING_VALUE_NONE. See
+ * https://github.com/hughsie/oars/blob/master/specification/oars-1.1.md */
 static gboolean
 app_is_content_rating_appropriate (GsApp *app, MctAppFilter *app_filter)
 {
        AsContentRating *rating = gs_app_get_content_rating (app);  /* (nullable) */
        g_autofree const gchar **oars_sections = mct_app_filter_get_oars_sections (app_filter);
+       AsContentRatingValue default_rating_value;
 
        if (rating == NULL && !app_is_expected_to_have_content_rating (app)) {
                /* Some apps, such as flatpak runtimes, are not expected to have
@@ -105,6 +109,9 @@ app_is_content_rating_appropriate (GsApp *app, MctAppFilter *app_filter)
        } else if (rating == NULL) {
                g_debug ("No OARS ratings provided for ‘%s’: assuming most extreme",
                         gs_app_get_unique_id (app));
+               default_rating_value = AS_CONTENT_RATING_VALUE_INTENSE;
+       } else {
+               default_rating_value = AS_CONTENT_RATING_VALUE_NONE;
        }
 
        for (gsize i = 0; oars_sections[i] != NULL; i++) {
@@ -116,10 +123,12 @@ app_is_content_rating_appropriate (GsApp *app, MctAppFilter *app_filter)
                if (rating != NULL)
                        rating_value = as_content_rating_get_value (rating, oars_sections[i]);
                else
-                       rating_value = AS_CONTENT_RATING_VALUE_INTENSE;
+                       rating_value = AS_CONTENT_RATING_VALUE_UNKNOWN;
+
+               if (rating_value == AS_CONTENT_RATING_VALUE_UNKNOWN)
+                       rating_value = default_rating_value;
 
-               if (rating_value == AS_CONTENT_RATING_VALUE_UNKNOWN ||
-                   filter_value == MCT_APP_FILTER_OARS_VALUE_UNKNOWN)
+               if (filter_value == MCT_APP_FILTER_OARS_VALUE_UNKNOWN)
                        continue;
                else if (convert_app_filter_oars_value (filter_value) < rating_value)
                        return FALSE;


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