Fix regexp error message in dictionaries#14557
Conversation
|
@XLTechie thanks for the review. I have addressed the raised points in the code and in the initial description. |
dc90aa4 to
936b97a
Compare
Co-authored-by: Sean Budd <seanbudd123@gmail.com>
|
@seanbudd, I have addressed review comments. However, it is not possible to use f-strings with gettext so I have turned back to % interpolation as it was before. I have also added two more lines to focus the field causing the regexp error as it was already done in case of empty pattern field error. |
|
However, it is not possible to use f-strings with gettext so I have turned back to % interpolation as it was before.
I meant only to suggest that for the log messages, not the user messages.
Apologies if I commented on the wrong line.
|
|
However, it is not possible to use f-strings with gettext so I have turned back to % interpolation as it was before.
It is possible, however, to use .format() with gettext, if you want to go
slightly more modern than % replacements in the user messages. See
globalCommands.py for examples, among others.
|
No worry, you commented on the correct line. But I have then added another extra f-string in an inappropriate place, i.e. where gettext is used. Regarding |
|
Hi, regarding formatted string literals (F strings) and string formatting, the former is not used in translatable strings due to security (translated messages can introduce strings that could crash Python), and using str.format allows translators to see more readable (and understandable) source text for translations. Thanks.
|
|
Agreed with @josephsl, the label in the format string e.g. |
seanbudd
left a comment
There was a problem hiding this comment.
Looks good to me, other than a minor syntax issue
See test results for failed build of commit 5ed1c6b852 |
…placement expression of dictionary
…t expression of dictionary (#14664) Fixes #14663 Fix-up of #14557 Summary of the issue: When reading text containing a non-regexp dictionary entry, if the replacement field contains some special characters (such as space, +, etc.), these characters are escaped with a backslash. Thus this backslash is heard in the text spoken by NVDA. Description of user facing changes No unappropriated backslash will be spoken by NVDA when the replacement field of a dictionary entry contains space or other special character. Description of development approach Use theString.replace('\\', '\\\\') instead of re.escape(theString). Indeed, it was well documented in the doc of re.escape: This function must not be used for the replacement string in sub() and subn(), only backslashes should be escaped.
Link to issue number:
Fixes #14556
Summary of the issue:
Dictionaries do not allow to use backslash character normally in the replacement field when regexp is not selected as entry type. When such a character is used, a message box complaining of a regexp error appears.
Description of user facing changes
Description of development approach
re.errorinstead of the too globalExceptionto catch only exceptions related to regexpsTesting strategy:
Manual tests:
Known issues with pull request:
None
Change log entries:
Bug fixes
It is now possible to use the backslash character in the replacement field of a dictionaries entry, when the type is not set to regular expression. (#14556)Code Review Checklist:
[x] Pull Request description: