From 9b6ce07612065a27dc4ab11dd2531394a83c6a06 Mon Sep 17 00:00:00 2001 From: Alan King Date: Thu, 13 Feb 2025 16:06:15 -0500 Subject: [PATCH] [#7795] iquery: Add test for query tab in where clause --- scripts/irods/test/test_iquery.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/scripts/irods/test/test_iquery.py b/scripts/irods/test/test_iquery.py index 2e5b95ce65..204228f353 100644 --- a/scripts/irods/test/test_iquery.py +++ b/scripts/irods/test/test_iquery.py @@ -152,3 +152,25 @@ def test_genquery2_maps_genquery_user_zone_columns_to_correct_database_columns__ query_string = f"select DATA_ACCESS_USER_NAME, DATA_ACCESS_USER_ZONE, count(DATA_ID) where DATA_NAME = '{data_name}' group by DATA_ACCESS_USER_NAME, DATA_ACCESS_USER_ZONE" json_string = json.dumps([[self.user.username, self.user.zone_name, '1']], separators=(',', ':')) self.user.assert_icommand(['iquery', query_string], 'STDOUT', [json_string]) + + def test_iquery_correctly_parses_queries_with_tabs_in_the_where_clause__issue_7795(self): + # Run a basic query to get the expected output. + query_string = f"select USER_ID where USER_NAME = '{self.user.username}'" + expected_output = self.user.assert_icommand(["iquery", query_string], "STDOUT")[1].strip() + expected_user_id = json.loads(expected_output)[0][0] + + # Now construct a query that should return the same results, but with a tab in the where clause. + query_string_with_tab_in_where_clause = query_string + "\tand USER_TYPE = 'rodsuser'" + + # iquest will fail because there is a tab in the where clause. + self.user.assert_icommand( + ["iquest", "%s", query_string_with_tab_in_where_clause], + "STDOUT", + "CAT_NO_ROWS_FOUND: Nothing was found matching your query") + + # iquery will succeed because it uses a real parser. + output = self.user.assert_icommand(["iquery", query_string_with_tab_in_where_clause], "STDOUT")[1].strip() + user_id = json.loads(output)[0][0] + + # ...should match. + self.assertEqual(user_id, expected_user_id)