Skip to contentSkip to conversation

test-runner: fix matching with --verbose

PATCH Applied James Prestwood 2 participants 2 messages Jun 21, 2022 – Jun 22, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test-runner: fix matching with --verbose

The new regex match update was actually matching way more than it should have due to how python's 'match' API works. 'match' will return successfully if zero or more characters match from the beginning of the string. In this case we actually need the entire regex to match otherwise we start matching all prefixes, for example:

"--verbose iwd" will match iwd, iwd-dhcp, iwd-acd, iwd-genl and iwd-tls.

Instead use re.fullmatch which requires the entire string to match the regex.

---
 tools/utils.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/utils.py +2 -2
index 3cee9a22..04f6d910 100644
@@ -8,7 +8,7 @@ import dbus
 
 from gi.repository import GLib
 from weakref import WeakValueDictionary
-from re import match
+from re import fullmatch
 
 from runner import RunnerCoreArgParse
 
@@ -98,7 +98,7 @@ class Process(subprocess.Popen):
 		# Handle any regex matches
 		for item in Process.testargs.verbose:
 			try:
-				if match(item, process):
+				if fullmatch(item, process):
 					return True
 			except Exception as e:
 				print("%s is not a valid regex" % item)
Signature · 1 line
2.34.1
#1 lore raw

Hi James,

Quoted 6 lines · James Prestwood

The new regex match update was actually matching way more than it should have due to how python's 'match' API works. 'match' will return successfully if zero or more characters match from the beginning of the string. In this case we actually need the entire regex to match otherwise we start matching all prefixes, for example:

Quoted 8 lines

"--verbose iwd" will match iwd, iwd-dhcp, iwd-acd, iwd-genl and iwd-tls.

Instead use re.fullmatch which requires the entire string to match the regex.

---
  tools/utils.py | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks.

Regards,
-Denis