]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
pytest: simplify and fix HEXDUMP_FILTER used in hexdumps
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Tue, 11 Jun 2024 23:34:36 +0000 (11:34 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 12 Jun 2024 08:14:34 +0000 (08:14 +0000)
The old test

   x if ((len(repr(chr(x))) == 3) and (x < 127)) else ord('.')

went through some contortions to see if the character was printable, and
it got it slightly wrong. The idea was that `repr(chr(97)` is "'a'",
while `repr(chr(167)` is "'\xa7'", which we can distinguish using the
length. But that miscategorised the backslash character, which is
represented as "'\\'", a string of length 4, so it was show as '.'
instead.

Instead we notice that the characters we want to print in a hexdump
are exactly those between 32 and 126, inclusive.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/tests/__init__.py

index 136dd2fc31697598a93775b717b27585fe553571..ef57309ab70f55eed0883f7ba3a5eeed40bfc50e 100644 (file)
@@ -57,7 +57,8 @@ from unittest import SkipTest
 BINDIR = os.path.abspath(os.path.join(os.path.dirname(__file__),
                                       "../../../../bin"))
 
-HEXDUMP_FILTER = bytearray([x if ((len(repr(chr(x))) == 3) and (x < 127)) else ord('.') for x in range(256)])
+# HEXDUMP_FILTER maps ASCII control characters to '.', printables to themselves
+HEXDUMP_FILTER = bytearray(x if (x > 31 and x < 127) else 46 for x in range(256))
 
 LDB_ERR_LUT = {v: k for k, v in vars(ldb).items() if k.startswith('ERR_')}