Skip to content

Commit

Permalink
a11y: Return correct start and end offsets
Browse files Browse the repository at this point in the history
This modifies ev_page_accessible_get_range_for_boundary to ensure that
the start and end offsets it returns are within the allowed range.

https://bugzilla.gnome.org/show_bug.cgi?id=777992

origin commit:
https://git.gnome.org/browse/evince/commit/?id=e95a4e3
  • Loading branch information
jascrain authored and raveit65 committed Apr 5, 2018
1 parent 7c7c7ef commit bc7af60
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions libview/ev-page-accessible.c
Expand Up @@ -543,32 +543,35 @@ ev_page_accessible_get_range_for_boundary (AtkText *text,
if (!log_attrs) if (!log_attrs)
return; return;


if (offset < 0 || offset >= n_attrs)
return;

switch (boundary_type) { switch (boundary_type) {
case ATK_TEXT_BOUNDARY_CHAR: case ATK_TEXT_BOUNDARY_CHAR:
start = offset; start = offset;
end = offset + 1; end = offset + 1;
break; break;
case ATK_TEXT_BOUNDARY_WORD_START: case ATK_TEXT_BOUNDARY_WORD_START:
for (start = offset; start >= 0 && !log_attrs[start].is_word_start; start--); for (start = offset; start > 0 && !log_attrs[start].is_word_start; start--);
for (end = offset + 1; end <= n_attrs && !log_attrs[end].is_word_start; end++); for (end = offset + 1; end < n_attrs && !log_attrs[end].is_word_start; end++);
break; break;
case ATK_TEXT_BOUNDARY_SENTENCE_START: case ATK_TEXT_BOUNDARY_SENTENCE_START:
for (start = offset; start >= 0; start--) { for (start = offset; start > 0; start--) {
if (log_attrs[start].is_mandatory_break && treat_as_soft_return (view, self->priv->page, log_attrs, start - 1)) if (log_attrs[start].is_mandatory_break && treat_as_soft_return (view, self->priv->page, log_attrs, start - 1))
continue; continue;
if (log_attrs[start].is_sentence_start) if (log_attrs[start].is_sentence_start)
break; break;
} }
for (end = offset + 1; end <= n_attrs; end++) { for (end = offset + 1; end < n_attrs; end++) {
if (log_attrs[end].is_mandatory_break && treat_as_soft_return (view, self->priv->page, log_attrs, end - 1)) if (log_attrs[end].is_mandatory_break && treat_as_soft_return (view, self->priv->page, log_attrs, end - 1))
continue; continue;
if (log_attrs[end].is_sentence_start) if (log_attrs[end].is_sentence_start)
break; break;
} }
break; break;
case ATK_TEXT_BOUNDARY_LINE_START: case ATK_TEXT_BOUNDARY_LINE_START:
for (start = offset; start >= 0 && !log_attrs[start].is_mandatory_break; start--); for (start = offset; start > 0 && !log_attrs[start].is_mandatory_break; start--);
for (end = offset + 1; end <= n_attrs && !log_attrs[end].is_mandatory_break; end++); for (end = offset + 1; end < n_attrs && !log_attrs[end].is_mandatory_break; end++);
break; break;
default: default:
/* The "END" boundary types are deprecated */ /* The "END" boundary types are deprecated */
Expand Down

0 comments on commit bc7af60

Please sign in to comment.