URL: https://github.com/freeipa/freeipa/pull/1585
Author: tiran
 Title: #1585: [Py3] Fix i18n test for Chinese translation
Action: opened

PR body:
"""
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 <slazn...@redhat.com>
Signed-off-by: Christian Heimes <chei...@redhat.com>
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/1585/head:pr1585
git checkout pr1585
From be9aed3291790be829531cc7804e97ad6e6ed300 Mon Sep 17 00:00:00 2001
From: Christian Heimes <chei...@redhat.com>
Date: Thu, 15 Feb 2018 10:00:07 +0100
Subject: [PATCH] [Py3] 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 <slazn...@redhat.com>
Signed-off-by: Christian Heimes <chei...@redhat.com>
---
 Makefile.am      |  2 +-
 ipatests/i18n.py | 23 +++++++++++++++--------
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 9bb1a94e9e..a4381dd071 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 9a3bf5b7f0..28593279f0 100755
--- a/ipatests/i18n.py
+++ b/ipatests/i18n.py
@@ -68,12 +68,15 @@
 
 #-------------------------------------------------------------------------------
 # 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)
-                         ]
+# Enforce ASCII mode so \w matches only ASCII chars. This avoids false
+# positives in Chinese translation.
+_substitution_regexps = [
+    re.compile(r'%[srduoxf]'),                    # e.g. %s
+    re.compile(r'%\(\w+\)[srduoxf]', re.ASCII),   # e.g. %(foo)s
+    re.compile(r'\$\w+', re.ASCII),               # e.g. $foo
+    re.compile(r'\${\w+}', re.ASCII),             # e.g. ${foo}
+    re.compile(r'\$\(\w+\)', re.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 +84,15 @@
 # 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])?', re.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*)([)}]?)', re.ASCII
+)
 # group 1: whitespace between $ and delimiter
 # group 2: begining delimiter
 # group 3: whitespace between beginning delmiter and variable
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org

Reply via email to