Skip to content

Commit 711fa23

Browse files
committed
Validate properties specified for sorting and grouping in index
views. Original patch from martin.v.loewis via: https://hg.python.org/tracker/roundup/rev/439bd3060df2 Applied by John Rouillard with some modification to properly identify if the bad property is a sort or grouping property. Tests added. Ideally we would never get bad sort/group properties but...
1 parent 9f5e53e commit 711fa23

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

CHANGES.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ Fixed:
132132
- issue2550850 anypy/email_.py uses BSPACE which is not defined in python 2.7
133133
Supplied a definition for BSPACE since it seems to not be defined
134134
anywhere. Reported by Dennis Boone. (John Rouillard)
135+
- Validate properties specified for sorting and grouping in index
136+
views. Original patch from martin.v.loewis via:
137+
https://hg.python.org/tracker/roundup/rev/439bd3060df2
138+
Applied by John Rouillard with some modification to properly
139+
identify if the bad property is a sort or grouping property. Tests
140+
added.
135141

136142
2016-01-11: 1.5.1
137143

roundup/cgi/templating.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,13 +2517,18 @@ def _parse_sort(self, var, name):
25172517
dirs.append(self.form.getfirst(dirkey))
25182518
if fields: # only try other special char if nothing found
25192519
break
2520+
cls = self.client.db.getclass(self.classname)
25202521
for f, d in map(None, fields, dirs):
25212522
if f.startswith('-'):
2522-
var.append(('-', f[1:]))
2523+
dir, propname = '-', f[1:]
25232524
elif d:
2524-
var.append(('-', f))
2525+
dir, propname = '-', f
25252526
else:
2526-
var.append(('+', f))
2527+
dir, propname = '+', f
2528+
if cls.get_transitive_prop(propname) is None:
2529+
self.client.add_error_message("Unknown %s property %s"%(name, propname))
2530+
else:
2531+
var.append((dir, propname))
25272532

25282533
def _form_has_key(self, name):
25292534
try:

test/test_cgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ def _make_client(self, form, classname='user', nodeid='1',
787787
cl.userid = userid
788788
cl.language = ('en',)
789789
cl._error_message = []
790+
cl._ok_message = []
790791
cl.template = template
791792
return cl
792793

@@ -986,6 +987,21 @@ def testSearchPermission(self):
986987
userid=chef, template='index')
987988
h = HTMLRequest(cl)
988989
self.assertEqual([x.id for x in h.batch()],['2', '3', '1'])
990+
self.assertEqual(cl._error_message, []) # test for empty _error_message when sort is valid
991+
self.assertEqual(cl._ok_message, []) # test for empty _ok_message when sort is valid
992+
993+
# Test for correct _error_message for invalid sort/group properties
994+
baddepsort = {'@action':'search','columns':'id','@sort':'dep'}
995+
baddepgrp = {'@action':'search','columns':'id','@group':'dep'}
996+
cl = self._make_client(baddepsort, classname='iss', nodeid=None,
997+
userid=chef, template='index')
998+
h = HTMLRequest(cl)
999+
self.assertEqual(cl._error_message, ['Unknown sort property dep'])
1000+
cl = self._make_client(baddepgrp, classname='iss', nodeid=None,
1001+
userid=chef, template='index')
1002+
h = HTMLRequest(cl)
1003+
self.assertEqual(cl._error_message, ['Unknown group property dep'])
1004+
9891005
cl = self._make_client(depgrp, classname='iss', nodeid=None,
9901006
userid=chef, template='index')
9911007
h = HTMLRequest(cl)

0 commit comments

Comments
 (0)