Merge pull request #441 from boxerab/fix-clear-screen-shell-injection

Avoid clear screen shell injection by using ANSI escape codes
This commit is contained in:
Vineet Suryan
2026-05-08 17:36:11 +02:00
committed by GitHub
2 changed files with 8 additions and 3 deletions
+7 -1
View File
@@ -4,7 +4,7 @@ import unittest
from io import StringIO from io import StringIO
from unittest.mock import patch from unittest.mock import patch
from whisper_live.utils import format_time, create_srt_file, print_transcript from whisper_live.utils import format_time, create_srt_file, print_transcript, clear_screen
class TestFormatTime(unittest.TestCase): class TestFormatTime(unittest.TestCase):
@@ -97,6 +97,12 @@ class TestCreateSrtFile(unittest.TestCase):
class TestPrintTranscript(unittest.TestCase): class TestPrintTranscript(unittest.TestCase):
@patch("sys.stdout", new_callable=StringIO)
def test_clear_screen_uses_ansi(self, mock_stdout):
clear_screen()
output = mock_stdout.getvalue()
self.assertIn("\033[H\033[2J", output)
@patch("sys.stdout", new_callable=StringIO) @patch("sys.stdout", new_callable=StringIO)
def test_print_plain_text(self, mock_stdout): def test_print_plain_text(self, mock_stdout):
text = ["Hello", " world"] text = ["Hello", " world"]
+1 -2
View File
@@ -1,4 +1,3 @@
import os
import textwrap import textwrap
import scipy import scipy
import numpy as np import numpy as np
@@ -8,7 +7,7 @@ from pathlib import Path
def clear_screen(): def clear_screen():
"""Clears the console screen.""" """Clears the console screen."""
os.system("cls" if os.name == "nt" else "clear") print("\033[H\033[2J", end="", flush=True)
def print_transcript(text, translated=False, timestamps=False): def print_transcript(text, translated=False, timestamps=False):