Skip to content

Commit

Permalink
[irods#5727] Add GenQuery2 test for embedded single quotes.
Browse files Browse the repository at this point in the history
  • Loading branch information
korydraughn authored and alanking committed Apr 9, 2024
1 parent b4c609a commit 8e4958c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions scripts/irods/test/test_iquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,23 @@ def test_iquery_supports_OR_operator__issue_4069(self):
query_string = f"select COLL_NAME where COLL_NAME = '{self.user.home_collection}' or COLL_NAME like '{self.admin.home_collection}' order by COLL_NAME"
json_string = json.dumps([[self.user.home_collection], [self.admin.home_collection]], separators=(',', ':'))
self.admin.assert_icommand(['iquery', query_string], 'STDOUT', json_string)

def test_iquery_supports_embedded_single_quotes__issue_5727(self):
# Create a collection containing an embedded single quote in the name.
collection = "issue'5727.c"
self.user.assert_icommand(['imkdir', collection])

# Create a data object containing an embedded single quote in the name.
data_object = "test_iquery_supports_embedded_single_quotes'__issue_5727"
self.user.assert_icommand(['istream', 'write', data_object], input='data')

# Show the GenQuery2 parser provides ways of dealing with embedded single quotes.
escaped_strings = [
data_object.replace("'", '\\x27'), # Uses hex value to escape single quote.
data_object.replace("'", "''") # Uses two single quotes to escape single quote like in SQL.
]
json_string = json.dumps([[data_object, self.user.session_collection]], separators=(',', ':'))
for escaped in escaped_strings:
query_string = f"select DATA_NAME, COLL_NAME where COLL_NAME = '{self.user.session_collection}' or DATA_NAME = '{escaped}'"
with self.subTest(f'escaped_string={escaped}'):
self.user.assert_icommand(['iquery', query_string], 'STDOUT', [json_string])

0 comments on commit 8e4958c

Please sign in to comment.