Mercurial > hg
comparison tests/run-tests.py @ 44449: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 |
comparison
equal
deleted
inserted
replaced
44448:55c443fcb4fc | 44449:ff72bd52d56a |
---|---|
1329 'HGCATAPULTSERVERPIPE', os.devnull | 1329 'HGCATAPULTSERVERPIPE', os.devnull |
1330 ) | 1330 ) |
1331 | 1331 |
1332 extraextensions = [] | 1332 extraextensions = [] |
1333 for opt in self._extraconfigopts: | 1333 for opt in self._extraconfigopts: |
1334 section, key = opt.encode('utf-8').split(b'.', 1) | 1334 section, key = _sys2bytes(opt).split(b'.', 1) |
1335 if section != 'extensions': | 1335 if section != 'extensions': |
1336 continue | 1336 continue |
1337 name = key.split(b'=', 1)[0] | 1337 name = key.split(b'=', 1)[0] |
1338 extraextensions.append(name) | 1338 extraextensions.append(name) |
1339 | 1339 |
1430 hgrc.write(b'address = localhost\n') | 1430 hgrc.write(b'address = localhost\n') |
1431 hgrc.write(b'ipv6 = %r\n' % self._useipv6) | 1431 hgrc.write(b'ipv6 = %r\n' % self._useipv6) |
1432 hgrc.write(b'server-header = testing stub value\n') | 1432 hgrc.write(b'server-header = testing stub value\n') |
1433 | 1433 |
1434 for opt in self._extraconfigopts: | 1434 for opt in self._extraconfigopts: |
1435 section, key = opt.encode('utf-8').split(b'.', 1) | 1435 section, key = _sys2bytes(opt).split(b'.', 1) |
1436 assert b'=' in key, ( | 1436 assert b'=' in key, ( |
1437 'extra config opt %s must ' 'have an = for assignment' % opt | 1437 'extra config opt %s must ' 'have an = for assignment' % opt |
1438 ) | 1438 ) |
1439 hgrc.write(b'[%s]\n%s\n' % (section, key)) | 1439 hgrc.write(b'[%s]\n%s\n' % (section, key)) |
1440 | 1440 |