Skip to content

Commit 0e936a9

Browse files
committed
net: strip OSC escape sequences from VM console output
Fedora 43 (systemd 256+) emits OSC 8003 session-tracking escape sequences in the terminal. The existing regex in vm_console_run_commands only stripped CSI sequences (ESC[…), leaving OSC sequences (ESC]…) in the parsed output. This broke any caller that parses console output, e.g. json.loads() in ip_specification tests. Extend the regex to also strip OSC sequences terminated by BEL or ST, per ECMA-48 specification. Signed-off-by: Sergei Volkov <sevolkov@redhat.com> Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2c5ec8d commit 0e936a9

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

utilities/virt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,8 +1495,8 @@ def vm_console_run_commands(
14951495
Dict of the commands outputs, where the key is the command and the value is the output as a list of lines.
14961496
"""
14971497
output = {}
1498-
# Source: https://www.tutorialspoint.com/how-can-i-remove-the-ansi-escape-sequences-from-a-string-in-python
1499-
ansi_escape = re.compile(r"(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]")
1498+
# Strip CSI (ESC[…) and OSC (ESC]…BEL/ST) terminal escape sequences
1499+
ansi_escape = re.compile(r"(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]|\x1B\][^\x07\x1B]*(?:\x07|\x1B\\)")
15001500
prompt = r"\$ "
15011501
with Console(vm=vm, prompt=prompt) as vmc:
15021502
for command in commands:

0 commit comments

Comments
 (0)