[orca] Web: Work harder to turn inaccessible links into something presentable



commit 8efac7844728c4f9bd041ec9299ab8e070dc19f1
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Tue Jan 26 12:31:35 2021 +0100

    Web: Work harder to turn inaccessible links into something presentable
    
    We were already parsing the URL of an inaccessible link in order to
    present something besides just "link" when one of these gains focus
    (e.g. via Tab). But we were checking to see if the basename we
    computed for the URL consisted only of alphabetic characters. This
    was done in order to filter out long gibberishy URLs like we see
    associated with ads. Being this strict, however, meant that a basename
    of "foo" would be presented, whereas a basename of "foo-bar" would not.
    Therefore, split the basename on "-" and "_" into a series of tokens.
    If each of those tokens consists solely of alphabetic characters,
    present it.

 src/orca/generator.py        |  4 ++--
 src/orca/script_utilities.py | 13 +++++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)
---
diff --git a/src/orca/generator.py b/src/orca/generator.py
index a79de21b2..ea9cc74f4 100644
--- a/src/orca/generator.py
+++ b/src/orca/generator.py
@@ -342,8 +342,8 @@ class Generator:
                 elif obj.parent and obj.parent.getRole() == pyatspi.ROLE_LINK:
                     link = obj.parent
                 if link:
-                    basename = self._script.utilities.linkBasename(link)
-                    if basename and basename.isalpha():
+                    basename = self._script.utilities.linkBasenameToName(link)
+                    if basename:
                         result.append(basename)
         # To make the unlabeled icons in gnome-panel more accessible.
         try:
diff --git a/src/orca/script_utilities.py b/src/orca/script_utilities.py
index 22e970e48..7c83d4b48 100644
--- a/src/orca/script_utilities.py
+++ b/src/orca/script_utilities.py
@@ -1766,6 +1766,19 @@ class Utilities:
 
         return list(filter(isNotAncestor, result))
 
+    def linkBasenameToName(self, obj):
+        basename = self.linkBasename(obj)
+        if not basename:
+            return ""
+
+        basename = re.sub(r"[-_]", " ", basename)
+        tokens = basename.split()
+        for token in tokens:
+            if not token.isalpha():
+                return ""
+
+        return basename
+
     @staticmethod
     def linkBasename(obj):
         """Returns the relevant information from the URI.  The idea is


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