From 2b7609b0d5f0b84076a91d5144e850a3a2fc90df Mon Sep 17 00:00:00 2001 From: ptiurin Date: Tue, 16 Jul 2024 09:14:40 +0100 Subject: [PATCH] test(FIR-34595): Add test that verifies parsing issue --- tests/unit/db/test_cursor.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/unit/db/test_cursor.py b/tests/unit/db/test_cursor.py index 25320fc085f..4e1cf1b757d 100644 --- a/tests/unit/db/test_cursor.py +++ b/tests/unit/db/test_cursor.py @@ -724,3 +724,31 @@ def query_callback_with_headers(request: Request, **kwargs) -> Response: assert len(cursor._set_parameters) == 0 assert bool(cursor.engine_url) is True, "engine url is not set" assert bool(cursor.database) is True, "database is not set" + + +@mark.xfail(reason="FIR-34595: sqlparse does not handle escape sequences correctly") +def test_cursor_parse_escape_sequence_correctly( + httpx_mock: HTTPXMock, + query_url: str, + query_callback: Callable, + cursor: Cursor, +): + """ + Verify that the query is parsed correctly when it contains escape sequences. + \ should be propagated as is, not as an escape, '' becomes a single '. + """ + query = r"SELECT ')\'');a';" + num_called = 0 + + def counter_callback(request: Request, **kwargs) -> Response: + nonlocal num_called + num_called += 1 + assert request.read() == bytes( + query, "utf-8" + ), "Query was modified by the parser" + return query_callback(request, **kwargs) + + httpx_mock.add_callback(counter_callback, url=query_url) + + cursor.execute(query) + assert num_called == 1, "Query was not parsed correctly"