diff options
author | Alejandro Piñeiro <apinheiro@igalia.com> | 2013-12-09 18:08:20 +0100 |
---|---|---|
committer | Alejandro Piñeiro <apinheiro@igalia.com> | 2013-12-09 18:08:20 +0100 |
commit | eacee483828a5f77e8bd80ae68edbf077549aa9e (patch) | |
tree | d1a653bbe846ce3764105a89f21bfcc855053113 | |
parent | 73aebcaa236fb2e78595d134bcf00b9a64bb8e14 (diff) | |
download | atk-eacee483828a5f77e8bd80ae68edbf077549aa9e.tar.gz |
role: add some checks on atk_role_register for wrong role names
Related with downstream bug:
https://bugzilla.redhat.com/show_bug.cgi?id=983891
-rwxr-xr-x | atk/atkobject.c | 20 | ||||
-rw-r--r-- | tests/testrole.c | 17 |
2 files changed, 35 insertions, 2 deletions
diff --git a/atk/atkobject.c b/atk/atkobject.c index 1848fb3..72cfbdd 100755 --- a/atk/atkobject.c +++ b/atk/atkobject.c @@ -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 (); diff --git a/tests/testrole.c b/tests/testrole.c index 593549e..2f5bacc 100644 --- a/tests/testrole.c +++ b/tests/testrole.c @@ -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; } |