Correctly escape sort-by columns in SQL (refs #189)

This commit is contained in:
Simon Willison 2018-04-08 19:25:14 -07:00 committed by Simon Willison
commit bfb19e3a17

View file

@ -616,10 +616,10 @@ class TableView(RowTableShared):
# Allow for custom sort order # Allow for custom sort order
sort = special_args.get('_sort') sort = special_args.get('_sort')
if sort: if sort:
order_by = sort order_by = escape_sqlite(sort)
sort_desc = special_args.get('_sort_desc') sort_desc = special_args.get('_sort_desc')
if sort_desc: if sort_desc:
order_by = '{} desc'.format(sort_desc) order_by = '{} desc'.format(escape_sqlite(sort_desc))
count_sql = 'select count(*) from {table_name} {where}'.format( count_sql = 'select count(*) from {table_name} {where}'.format(
table_name=escape_sqlite(table), table_name=escape_sqlite(table),