Skip to content

Commit 7a62744

Browse files
Committed edited fix for issue2550712 by Cedric Krier.
1 parent ebc563a commit 7a62744

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Fixed:
4343
Reported and fixed by Ralf Hemmecke. (Bernhard)
4444
- issue2550715: IndexError when requesting non-existing file via http.
4545
Reported and fixed by C�dric Krier. (Bernhard)
46+
- issue2550712: exportcsvaction errors poorly when given invalid columns.
47+
Reported by Will Kahn-Greene, fixed by C�dric Krier. (Bernhard)
4648
- issue2550695: 'No sort or group' settings not retained when editing queries.
4749
Reported and fixed by John Kristensen. Tested by Satchidanand Haridas.
4850
(Bernhard)

roundup/cgi/actions.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,18 @@ def handle(self):
10351035
columns = request.columns
10361036
klass = self.db.getclass(request.classname)
10371037

1038+
# check if all columns exist on class
1039+
# the exception must be raised before sending header
1040+
props = klass.getprops()
1041+
for cname in columns:
1042+
if cname not in props:
1043+
# TODO raise exceptions.NotFound(.....) does not give message
1044+
# so using SeriousError instead
1045+
self.client.response_code = 404
1046+
raise exceptions.SeriousError(
1047+
self._('Column "%(column)s" not found on %(class)s')
1048+
% {'column': cgi.escape(cname), 'class': request.classname})
1049+
10381050
# full-text search
10391051
if request.search_text:
10401052
matches = self.db.indexer.search(

test/test_cgi.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,14 +930,26 @@ def testCSVExport(self):
930930
'8,resolved\r\n',
931931
output.getvalue())
932932

933+
def testCSVExportBadColumnName(self):
934+
cl = self._make_client({'@columns': 'falseid,name'}, nodeid=None,
935+
userid='1')
936+
cl.classname = 'status'
937+
output = StringIO.StringIO()
938+
cl.request = MockNull()
939+
cl.request.wfile = output
940+
self.assertRaises(exceptions.SeriousError,
941+
actions.ExportCSVAction(cl).handle)
942+
933943
def testCSVExportFailPermission(self):
934944
cl = self._make_client({'@columns': 'id,email,password'}, nodeid=None,
935945
userid='2')
936946
cl.classname = 'user'
937947
output = StringIO.StringIO()
938948
cl.request = MockNull()
939949
cl.request.wfile = output
940-
self.assertRaises(exceptions.Unauthorised,
950+
# used to be self.assertRaises(exceptions.Unauthorised,
951+
# but not acting like the column name is not found
952+
self.assertRaises(exceptions.SeriousError,
941953
actions.ExportCSVAction(cl).handle)
942954

943955

0 commit comments

Comments
 (0)