ttfw: fix incorrect length when flush data cache after expect:

data cache is unicode. while we use bytes in RegEx expect. The index of
matched pattern is calculated with bytes, could be different from
unicode. Now we fix this issue by using unicode in expect.
This commit is contained in:
He Yin Ling
2021-07-01 17:48:53 +08:00
committed by bot
parent b79778d273
commit 1708febe48

View File

@@ -548,13 +548,11 @@ class BaseDUT(object):
:return: match groups if match succeed otherwise None :return: match groups if match succeed otherwise None
""" """
ret = None ret = None
if isinstance(pattern.pattern, type(u'')): if isinstance(pattern.pattern, bytes):
pattern = re.compile(BaseDUT.u_to_bytearray(pattern.pattern)) pattern = re.compile(_decode_data(pattern.pattern))
if isinstance(data, type(u'')):
data = BaseDUT.u_to_bytearray(data)
match = pattern.search(data) match = pattern.search(data)
if match: if match:
ret = tuple(None if x is None else x.decode() for x in match.groups()) ret = tuple(x for x in match.groups())
index = match.end() index = match.end()
else: else:
index = -1 index = -1