/ tests / cli / test_cli_bracketed_paste_sanitizer.py
test_cli_bracketed_paste_sanitizer.py
 1  """Tests for defensive bracketed-paste wrapper stripping in the CLI."""
 2  
 3  from cli import _strip_leaked_bracketed_paste_wrappers
 4  
 5  
 6  class TestStripLeakedBracketedPasteWrappers:
 7      def test_plain_text_unchanged(self):
 8          text = "hello world"
 9          assert _strip_leaked_bracketed_paste_wrappers(text) == text
10  
11      def test_strips_canonical_escape_wrappers(self):
12          text = "\x1b[200~hello\x1b[201~"
13          assert _strip_leaked_bracketed_paste_wrappers(text) == "hello"
14  
15      def test_strips_visible_caret_escape_wrappers(self):
16          text = "^[[200~hello^[[201~"
17          assert _strip_leaked_bracketed_paste_wrappers(text) == "hello"
18  
19      def test_strips_degraded_bracket_only_wrappers(self):
20          text = "[200~hello[201~"
21          assert _strip_leaked_bracketed_paste_wrappers(text) == "hello"
22  
23      def test_strips_degraded_bracket_only_wrappers_after_whitespace(self):
24          text = "prefix [200~hello[201~ suffix"
25          assert _strip_leaked_bracketed_paste_wrappers(text) == "prefix hello suffix"
26  
27      def test_strips_wrapper_fragments_at_boundaries(self):
28          text = "00~hello world01~"
29          assert _strip_leaked_bracketed_paste_wrappers(text) == "hello world"
30  
31      def test_strips_wrapper_fragments_after_whitespace(self):
32          text = "prefix 00~hello world01~ suffix"
33          assert _strip_leaked_bracketed_paste_wrappers(text) == "prefix hello world suffix"
34  
35      def test_does_not_strip_non_wrapper_00_tilde_in_normal_text(self):
36          text = "build00~tag should stay"
37          assert _strip_leaked_bracketed_paste_wrappers(text) == text
38  
39      def test_does_not_strip_non_wrapper_bracket_forms_in_normal_text(self):
40          text = "literal[200~tag and literal[201~tag should stay"
41          assert _strip_leaked_bracketed_paste_wrappers(text) == text
42  
43      def test_preserves_multiline_content_while_stripping_wrappers(self):
44          text = "^[[200~line 1\nline 2\nline 3^[[201~"
45          assert _strip_leaked_bracketed_paste_wrappers(text) == "line 1\nline 2\nline 3"
46  
47      def test_preserves_multiline_content_while_stripping_degraded_bracket_only_wrappers(self):
48          text = "[200~line 1\nline 2\nline 3[201~"
49          assert _strip_leaked_bracketed_paste_wrappers(text) == "line 1\nline 2\nline 3"