From d3833d376cd87cf851eb2bc84a7786c64bd54131 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Tue, 28 May 2024 09:26:15 -0700 Subject: [PATCH] check-needles: tweak the handling of send_key_until_needlematch The previous way of doing this isn't really safe. It assumes we will find at least one string literal on any line containing send_key_until_needlematch, and strips the last one, on the basis it must be the key to press. But if the key to press is an unquoted variable, this will strip the tag instead. And if both the key to press and the tag are unquoted variables, this will strip the most recent string literal we put into the global list from some *other* line! So instead let's try to be a bit smarter about how we parse send_key_until_needlematch lines - just stripping out everything after the first comma after "send_key_until_needlematch" - and drop the dangerous "pop the last item from the list" logic. This way we should always only find the needle to match, if it's a string literal, as for other directives. We should never reach the key to press so we don't need to worry about taking it out. Signed-off-by: Adam Williamson --- check-needles.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/check-needles.py b/check-needles.py index 6873140e..f00c2fba 100755 --- a/check-needles.py +++ b/check-needles.py @@ -84,13 +84,16 @@ for testpath in testpaths: start = line.find(matchfunc) # fortunately `find` returns -1 for 'no match' if start > -1: - for match in DOUBLEQUOTERE.finditer(line[start:]): - testtags.append(match[1]) - for match in SINGLEQUOTERE.finditer(line[start:]): - testtags.append(match[1]) + matcharea = line[start:] if matchfunc == "send_key_until_needlematch": - # strip last match because it'll be the key to hit - testtags.pop() + # this needs some special handling - we need + # to leave out the key to press, which should + # come after the first comma + matcharea = matcharea.split(",")[0] + for match in DOUBLEQUOTERE.finditer(matcharea): + testtags.append(match[1]) + for match in SINGLEQUOTERE.finditer(matcharea): + testtags.append(match[1]) # filter the list a bit for matches that aren't tags. Almost all our # tags have a - or an _ in them, except a small number of weirdos;