diff options
author | Christian Heimes <cheimes@redhat.com> | 2018-02-15 10:00:07 +0100 |
---|---|---|
committer | Christian Heimes <cheimes@redhat.com> | 2018-02-15 11:45:31 +0100 |
commit | 0ee3a267112dfafe12726fb185a4ce260c67aff7 (patch) | |
tree | 74c545954874279aa93cce424b84a19fa8a4e245 | |
parent | a319a378d7913ea7af5ce360fc0a18ae9b889da0 (diff) | |
download | freeipa-0ee3a267112dfafe12726fb185a4ce260c67aff7.tar.gz freeipa-0ee3a267112dfafe12726fb185a4ce260c67aff7.tar.xz freeipa-0ee3a267112dfafe12726fb185a4ce260c67aff7.zip |
Fix i18n test for Chinese translation
Python 3's regular expression default to full range of unicode
characters. Restrict \w matches to ASCII and drop \b suffix check to fix
a problem with validation the Chinese translation zh_CN.
Co-Authored-By: Stanislav Laznicka <slaznick@redhat.com>
Signed-off-by: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Stanislav Laznicka <slaznick@redhat.com>
-rw-r--r-- | Makefile.am | 2 | ||||
-rwxr-xr-x | ipatests/i18n.py | 27 |
2 files changed, 19 insertions, 10 deletions
diff --git a/Makefile.am b/Makefile.am index 9bb1a94e9..a4381dd07 100644 --- a/Makefile.am +++ b/Makefile.am @@ -177,7 +177,7 @@ if WITH_PYTHON3 @ # just tests, aci, api and pylint on Python 3 PYTHONPATH=$(abspath $(top_srcdir)) $(PYTHON3) ipatests/ipa-run-tests \ --ipaclient-unittests - $(MAKE) $(AM_MAKEFLAGS) PYTHON=$(PYTHON3) acilint apilint pylint + $(MAKE) $(AM_MAKEFLAGS) PYTHON=$(PYTHON3) acilint apilint polint pylint else @echo "WARNING: python3 not available" endif diff --git a/ipatests/i18n.py b/ipatests/i18n.py index 9a3bf5b7f..521fc30c4 100755 --- a/ipatests/i18n.py +++ b/ipatests/i18n.py @@ -66,14 +66,19 @@ page_width = 80 section_seperator = '=' * page_width entry_seperator = '-' * page_width -#------------------------------------------------------------------------------- +# Python 3: Enforce ASCII mode so \w matches only ASCII chars. This avoids +# false positives in Chinese translation. +ASCII = getattr(re, "ASCII", 0) + +# -------------------------------------------------------------------------- # For efficiency compile these regexps just once -_substitution_regexps = [re.compile(r'%[srduoxf]\b'), # e.g. %s - re.compile(r'%\(\w+\)[srduoxf]\b'), # e.g. %(foo)s - re.compile(r'\$\w+'), # e.g. $foo - re.compile(r'\${\w+}'), # e.g. ${foo} - re.compile(r'\$\(\w+\)') # e.g. $(foo) - ] +_substitution_regexps = [ + re.compile(r'%[srduoxf]'), # e.g. %s + re.compile(r'%\(\w+\)[srduoxf]', ASCII), # e.g. %(foo)s + re.compile(r'\$\w+', ASCII), # e.g. $foo + re.compile(r'\${\w+}', ASCII), # e.g. ${foo} + re.compile(r'\$\(\w+\)', ASCII) # e.g. $(foo) +] # Python style substitution, e.g. %(foo)s # where foo is the key and s is the format char # group 1: whitespace between % and ( @@ -81,11 +86,15 @@ _substitution_regexps = [re.compile(r'%[srduoxf]\b'), # e.g. %s # group 3: whitespace between key and ) # group 4: whitespace between ) and format char # group 5: format char -_python_substitution_regexp = re.compile(r'%(\s*)\((\s*)\w+(\s*)\)(\s*)([srduoxf]\b)?') +_python_substitution_regexp = re.compile( + r'%(\s*)\((\s*)\w+(\s*)\)(\s*)([srduoxf])?', ASCII +) # Shell style substitution, e.g. $foo $(foo) ${foo} # where foo is the variable -_shell_substitution_regexp = re.compile(r'\$(\s*)([({]?)(\s*)\w+(\s*)([)}]?)') +_shell_substitution_regexp = re.compile( + r'\$(\s*)([({]?)(\s*)\w+(\s*)([)}]?)', ASCII +) # group 1: whitespace between $ and delimiter # group 2: begining delimiter # group 3: whitespace between beginning delmiter and variable |