Skip to content

Gracefully handle regular expression errors in speech dictionaries#10421

Merged
michaelDCurran merged 2 commits into
masterfrom
i10334
Oct 28, 2019
Merged

Gracefully handle regular expression errors in speech dictionaries#10421
michaelDCurran merged 2 commits into
masterfrom
i10334

Conversation

@michaelDCurran

@michaelDCurran michaelDCurran commented Oct 25, 2019

Copy link
Copy Markdown
Member

Link to issue number:

Fixes #10334

Summary of the issue:

In Python 3, re.sub raises re.error if a numeric replacement group is specified yet there is no matching group in the pattern. Python 2, silently ignored this.
In the past, users have deliberetly or otherwise created entries that are invalid in this way, but in NVDA 2019.2.1 and lower were just silently ignored. Now, they break NVDA in a way such that no speech works while those entries exist.

Description of how this pull request fixes the issue:

NVDA will now catch re.error, log the error, remove the entry from meory, and continue on processing other entries.

Testing performed:

Tested with the default.dic provided in #10334. Plus created several other invalid and valid entries, both in the default dictionary and temporary dictionary.
The invalid entries were logged once and then no longer processed.

Known issues with pull request:

None.

Change log entry:

Bug fixes:
Invalid regular expressions in speech dictionaries no longer completely break speech in NVDA. (#10334)

…ssing text for a given dictionary entry, log an error, remove the entry from memory, and continue processing further entries.
@AppVeyorBot

Copy link
Copy Markdown

PR introduces Flake8 errors 😲

See test results for Failed build of commit d9c9cba4ef

text = entry.sub(text)
except re.error as exc:
dictName = self.fileName or "temporary dictionary"
log.error(f"Invalid dictionary entry {index+1} in {dictName}: \"{entry.pattern}\", {exc}")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.error(f"Invalid dictionary entry {index+1} in {dictName}: \"{entry.pattern}\", {exc}")
log.error(f"Invalid dictionary entry {index+1} in {dictName}: {entry.pattern!r}, {exc}")

@LeonarddeR LeonarddeR left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APart from the only comment I made about the error log, this looks fine!

@michaelDCurran

michaelDCurran commented Oct 27, 2019 via email

Copy link
Copy Markdown
Member Author

@LeonarddeR

LeonarddeR commented Oct 28, 2019 via email

Copy link
Copy Markdown
Collaborator

@JulienCochuyt

Copy link
Copy Markdown
Contributor

Change log entry:

Bug fixes:
Invalid regular expressions in speech dictionaries no longer completely break speech in NVDA. (#10172

@michaelDCurran, seems PR #10172 is not the one you meant to reference here.

@michaelDCurran michaelDCurran merged commit 524e48d into master Oct 28, 2019
@nvaccessAuto nvaccessAuto added this to the 2019.3 milestone Oct 28, 2019
michaelDCurran added a commit that referenced this pull request Oct 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NVDA not speaking when installing alpha

5 participants