@@ -1793,27 +1793,34 @@ def test_no_newline(self):
17931793 env = os .environ .copy ()
17941794 env .pop ("PYTHON_BASIC_REPL" , "" )
17951795 env ["PYTHON_BASIC_REPL" ] = "1"
1796+
1797+ commands = "print('Something pretty long', end='')\n exit()\n "
17961798 expected_output_sequence = "Something pretty long>>> exit()"
1797- basic_output , basic_exit_code = self .run_repl ("print('Something pretty long', end='')\n exit()\n " , env = env )
1799+
1800+ basic_output , basic_exit_code = self .run_repl (commands , env = env )
17981801 self .assertEqual (basic_exit_code , 0 )
17991802 self .assertIn (expected_output_sequence , basic_output )
18001803
1801- output , exit_code = self .run_repl ("print('Something pretty long', end='') \n exit() \n " )
1804+ output , exit_code = self .run_repl (commands )
18021805 self .assertEqual (exit_code , 0 )
18031806
18041807 # Define escape sequences that don't affect cursor position or visual output
1805- bracketed_paste_mode = r'\x1b\[\?2004[hl]' # Enable/disable bracketed paste
1808+ bracketed_paste_mode = r'\x1b\[\?2004[hl]' # Enable/disable bracketed paste
18061809 application_cursor_keys = r'\x1b\[\?1[hl]' # Enable/disable application cursor keys
1807- application_keypad_mode = r'\x1b[=>]' # Enable/disable application keypad
1808- insert_character = r'\x1b\[\d+@ ' # Insert character sequences
1810+ application_keypad_mode = r'\x1b[=>]' # Enable/disable application keypad
1811+ insert_character = r'\x1b\[1@(?=[ -~]) ' # Insert exactly 1 char (safe form)
18091812 cursor_visibility = r'\x1b\[\?25[hl]' # Show/hide cursor
18101813 cursor_blinking = r'\x1b\[\?12[hl]' # Start/stop cursor blinking
1811-
1812- # Remove only non-visual terminal control sequences (NOT cursor movement)
1813- cleaned_output = re .sub (
1814- f'{ bracketed_paste_mode } |{ application_cursor_keys } |{ application_keypad_mode } |{ insert_character } |{ cursor_visibility } |{ cursor_blinking } ' ,
1815- '' ,
1816- output
1817- )
1818-
1814+ device_attributes = r'\x1b\[\?[01]c' # Device Attributes (DA) queries/responses
1815+
1816+ safe_escapes = re .compile (
1817+ f'{ bracketed_paste_mode } |'
1818+ f'{ application_cursor_keys } |'
1819+ f'{ application_keypad_mode } |'
1820+ f'{ insert_character } |'
1821+ f'{ cursor_visibility } |'
1822+ f'{ cursor_blinking } |'
1823+ f'{ device_attributes } '
1824+ )
1825+ cleaned_output = safe_escapes .sub ('' , output )
18191826 self .assertIn (expected_output_sequence , cleaned_output )
0 commit comments