role: add some checks on atk_role_register for wrong role names
authorAlejandro Piñeiro <apinheiro@igalia.com>
Mon, 9 Dec 2013 17:08:20 +0000 (18:08 +0100)
committerAlejandro Piñeiro <apinheiro@igalia.com>
Mon, 9 Dec 2013 17:08:20 +0000 (18:08 +0100)
Related with downstream bug:
https://bugzilla.redhat.com/show_bug.cgi?id=983891

atk/atkobject.c
tests/testrole.c

index 1848fb3..72cfbdd 100755 (executable)
@@ -896,13 +896,29 @@ atk_object_ref_relation_set (AtkObject *accessible)
  * atk_role_register:
  * @name: a character string describing the new role.
  *
- * Registers the role specified by @name.
+ * Registers the role specified by @name. @name must be a meaningful
+ * name. So it should not be empty, or consisting on whitespaces.
  *
- * Returns: an #AtkRole for the new role.
+ * Returns: an #AtkRole for the new role if added
+ * properly. ATK_ROLE_INVALID in case of error.
  **/
 AtkRole
 atk_role_register (const gchar *name)
 {
+  gboolean valid = FALSE;
+  gint i = 0;
+  glong length = g_utf8_strlen (name, -1);
+
+  for (i=0; i < length; i++) {
+    if (name[i]!=' ') {
+      valid = TRUE;
+      break;
+    }
+  }
+
+  if (!valid)
+    return ATK_ROLE_INVALID;
+
   if (!role_names)
     initialize_role_names ();
 
index 593549e..2f5bacc 100644 (file)
@@ -80,6 +80,23 @@ test_role (void)
       g_print ("Unexpected name for undefined role %s\n", name);
       result = FALSE;
     }
+
+  role1 = atk_role_register ("");
+  if (role1 != ATK_ROLE_INVALID)
+    {
+      g_print ("atk_role_register allowed to register empty string, but this is "
+               "an invalid role name\n");
+      result = FALSE;
+    }
+
+  role1 = atk_role_register ("   ");
+  if (role1 != ATK_ROLE_INVALID)
+    {
+      g_print ("atk_role_register allowed to register all whitespace string, but "
+               "that is an invalid role name \n");
+      result = FALSE;
+    }
+
   return result;
 }