2222
2323_INVALID_UTF8_BINARY = b"\x00 \x00 \x00 \x00 \x00 \x00 \x81 \xff "
2424_BINARY_TEXT = "0x00000000000081ff"
25+ _UTF8_JSON_BINARY = b'{"a": 1, "b": [1, 2, 3]}'
26+ _UTF8_JSON_TEXT = '{"a": 1, "b": [1, 2, 3]}'
2527
2628
2729@pytest .mark .parametrize (
@@ -44,6 +46,35 @@ def test_binary_column_is_stringified_before_arrow_measurement(value: object) ->
4446 assert table .get_cell_at (Coordinate (0 , 0 )) == _BINARY_TEXT
4547
4648
49+ @pytest .mark .parametrize (
50+ "value" ,
51+ [
52+ _UTF8_JSON_BINARY ,
53+ bytearray (_UTF8_JSON_BINARY ),
54+ memoryview (_UTF8_JSON_BINARY ),
55+ ],
56+ ids = ["bytes" , "bytearray" , "memoryview" ],
57+ )
58+ def test_utf8_binary_column_is_decoded_as_text (value : object ) -> None :
59+ table = SqlitDataTable (
60+ data = {"binary" : [value ]},
61+ column_labels = ["binary" ],
62+ )
63+
64+ assert table .backend is not None
65+ assert table .backend .column_content_widths == [len (_UTF8_JSON_TEXT )]
66+ assert table .get_cell_at (Coordinate (0 , 0 )) == _UTF8_JSON_TEXT
67+
68+
69+ def test_incrementally_added_utf8_binary_is_decoded_as_text () -> None :
70+ table = SqlitDataTable (data = {"binary" : ["initial" ]}, column_labels = ["binary" ])
71+
72+ table .add_rows ([(_UTF8_JSON_BINARY ,)])
73+
74+ assert table .backend is not None
75+ assert table .get_cell_at (Coordinate (1 , 0 )) == _UTF8_JSON_TEXT
76+
77+
4778def test_incrementally_added_binary_is_stringified () -> None :
4879 table = SqlitDataTable (data = {"binary" : ["initial" ]}, column_labels = ["binary" ])
4980
@@ -139,3 +170,34 @@ async def test_decimal_incremental_backend_stringifies_binary_column() -> None:
139170 _BINARY_TEXT
140171 )
141172 assert app .results_table .get_cell_at (Coordinate (0 , 2 )) == _BINARY_TEXT
173+
174+
175+ @pytest .mark .asyncio
176+ async def test_view_cell_tooltip_does_not_parse_markup () -> None :
177+ from rich .text import Text
178+
179+ payload = b'{"path": "[/api/v1]", "tags": ["a", "b"]}'
180+ connection = create_test_connection ("test-db" , "sqlite" )
181+ services = build_test_services (
182+ connection_store = MockConnectionStore ([connection ]),
183+ settings_store = MockSettingsStore ({"theme" : "tokyo-night" }),
184+ )
185+ app = SSMSTUI (services = services )
186+
187+ async with app .run_test (size = (120 , 40 )) as pilot :
188+ await pilot .pause ()
189+ await app ._display_query_results (
190+ columns = ["payload" ],
191+ rows = [(payload ,)],
192+ row_count = 1 ,
193+ truncated = False ,
194+ elapsed_ms = 0 ,
195+ )
196+ await pilot .pause (0.05 )
197+ app .results_table .cursor_coordinate = Coordinate (0 , 0 )
198+ app .action_view_cell ()
199+ await pilot .pause (0.05 )
200+
201+ tooltip = app .results_table .tooltip
202+ assert isinstance (tooltip , Text )
203+ assert tooltip .plain == payload .decode ("utf-8" )
0 commit comments