Skip to content

Commit 8f9c282

Browse files
mniestrojnashif
authored andcommitted
twister: pytest: escape expected command regex
When sending commands containing something like "AT+CFUN" the expected regex was not escaped and as a result such regex never matched what has been echoed over serial. Escape all commands with re.escape() so that echoed shell commands are always matched, even when they contain special characters (like '+' in the example above). Signed-off-by: Marcin Niestroj <[email protected]>
1 parent d5b1a7d commit 8f9c282

File tree

1 file changed

+1
-1
lines changed
  • scripts/pylib/pytest-twister-harness/src/twister_harness/helpers

1 file changed

+1
-1
lines changed

scripts/pylib/pytest-twister-harness/src/twister_harness/helpers/shell.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def exec_command(self, command: str, timeout: float | None = None, print_output:
5858
timeout = timeout or self.base_timeout
5959
command_ext = f'{command}\n\n'
6060
regex_prompt = re.escape(self.prompt)
61-
regex_command = f'.*{command}'
61+
regex_command = f'.*{re.escape(command)}'
6262
self._device.clear_buffer()
6363
self._device.write(command_ext.encode())
6464
lines: list[str] = []

0 commit comments

Comments
 (0)