changeset 44469:ff72bd52d56a

tests: avoid implicit conversion of str to unicode On Python 2, str.encode('utf-8') implicitly converts the string to unicode and then back to str. Using _sys2bytes() ensures that opt is only encoded on Python 3, where opt is unicode. Although contrived, before this change, a UnicodeDecodeError could be triggered on Python 2 when passing non-ascii values to --extra-config-opt.
author Manuel Jacob <me@manueljacob.de>
date Fri, 06 Mar 2020 10:52:44 +0100
parents 55c443fcb4fc
children 9d2b2df2c2ba
files tests/run-tests.py
diffstat 1 files changed, 2 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Fri Mar 06 09:50:57 2020 +0100
+++ b/tests/run-tests.py	Fri Mar 06 10:52:44 2020 +0100
@@ -1331,7 +1331,7 @@
 
         extraextensions = []
         for opt in self._extraconfigopts:
-            section, key = opt.encode('utf-8').split(b'.', 1)
+            section, key = _sys2bytes(opt).split(b'.', 1)
             if section != 'extensions':
                 continue
             name = key.split(b'=', 1)[0]
@@ -1432,7 +1432,7 @@
             hgrc.write(b'server-header = testing stub value\n')
 
             for opt in self._extraconfigopts:
-                section, key = opt.encode('utf-8').split(b'.', 1)
+                section, key = _sys2bytes(opt).split(b'.', 1)
                 assert b'=' in key, (
                     'extra config opt %s must ' 'have an = for assignment' % opt
                 )