Skip to content

Commit

Permalink
1.7.1dev: merge [17778] from 1.6-stable (fix for #13687)
Browse files Browse the repository at this point in the history
git-svn-id: http://trac.edgewall.org/intertrac/log:/trunk@17779 af82e41b-90c4-0310-8c96-b1721e28e2e2
  • Loading branch information
jomae committed Apr 21, 2024
2 parents f8b4704 + 8f20098 commit 8fb2bf0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
7 changes: 4 additions & 3 deletions trac/ticket/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,10 +938,11 @@ def _send_sql(self, req, id, title, description, sql):
req.perm(self.realm, id).require('REPORT_SQL_VIEW')

out = io.BytesIO()
out.write(b'-- ## %s: %s ## --\n\n' % (id, title.encode('utf-8')))
out.write(b'-- ## %d: %s ## --\n\n' % (id, title.encode('utf-8')))
if description:
lines = description.encode('utf-8').splitlines()
out.write(b'-- %s\n\n' % '\n-- '.join(lines))
for line in description.encode('utf-8').splitlines():
out.write(b'-- %s\n' % line)
out.write(b'\n')
out.write(sql.encode('utf-8'))
data = out.getvalue()

Expand Down
36 changes: 36 additions & 0 deletions trac/ticket/tests/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,42 @@ def test_csv_escape(self):
b'value, needs escaped",0\r\n',
req.response_sent.getvalue())

def test_send_sql(self):
with self.env.db_query as db:
cast_priority = db.cast('p.value', 'int')
expected = """\
-- ## 1: Active Tickets ## --
-- * List all active tickets by priority.
-- * Color each row based on priority.
SELECT p.value AS __color__,
t.id AS ticket, t.summary, t.component, t.version, t.milestone,
t.type AS type, t.owner, t.status, t.time AS created,
t.changetime AS _changetime, t.description AS _description,
t.reporter AS _reporter
FROM ticket t
LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority'
WHERE t.status <> 'closed'
ORDER BY {cast_priority}, t.milestone, t.type, t.time
""".format(**locals()).encode('utf-8')
req = MockRequest(self.env, path_info='/report/1',
arg_list=[('format', 'sql')])
self.assertTrue(self.report_module.match_request(req))
self.assertRaises(RequestDone, self.report_module.process_request, req)
self.assertEqual(expected, req.response_sent.getvalue())

def test_send_sql_without_description(self):
rid = self._insert_report('No description', 'SELECT 42\n', '')
expected = ('-- ## {rid}: No description ## --\n'
'\n'
'SELECT 42\n').format(**locals()).encode('utf-8')
req = MockRequest(self.env, path_info='/report/%d' % rid,
arg_list=[('format', 'sql')])
self.assertTrue(self.report_module.match_request(req))
self.assertRaises(RequestDone, self.report_module.process_request, req)
self.assertEqual(expected, req.response_sent.getvalue())

def test_saved_custom_query_redirect(self):
query = 'query:?type=résumé'
rid = self._insert_report('redirect', query, '')
Expand Down

0 comments on commit 8fb2bf0

Please sign in to comment.