Skip to content

Commit bcd9215

Browse files
committed
fix(web): issue2551406 - dont crash when handed invalid @template=a|b|c
Only two template cases (ok and error) are handled. Presence of second '|' caused crash. Discovered/patch provided by Christof Meerwald (cmeerw).
1 parent 0b7a2a0 commit bcd9215

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ Fixed:
9292
- issue2551323: remove functions used for XHTML template
9393
support. XHTML was deprecated in Roundup 2.3.0 and an invalid value
9494
in 2.4.0.
95+
- issue2551406: 'Templating Error: too many values to unpack' crash
96+
fixed. (reported by and patch Christof Meerwald, commit/test John
97+
Rouillard)
9598

9699
Features:
97100

roundup/cgi/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2195,7 +2195,7 @@ def selectTemplate(self, name, view):
21952195
# templates, just leave view alone.
21962196
if (view and view.find('|') != -1):
21972197
# we have alternate templates, parse them apart.
2198-
(oktmpl, errortmpl) = view.split("|", 2)
2198+
(oktmpl, errortmpl) = view.split("|", 1)
21992199

22002200
# Choose the right template
22012201
view = errortmpl if self._error_message else oktmpl

test/test_cgi.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,6 +2941,39 @@ def testRenderAltTemplates(self):
29412941
sha1sum = '<!-- SHA: 952568414163cd12b2e89e91e59ef336da64fbbe -->'
29422942
self.assertNotEqual(-1, result.index(sha1sum))
29432943

2944+
def testRenderAltTemplatesError(self):
2945+
# check that an error is reported to user when rendering using
2946+
# @template=oktempl|errortmpl|oops|foo
2947+
2948+
# template names can not include |
2949+
2950+
# set up the client;
2951+
# run determine_context to set the required client attributes
2952+
# run renderContext(); check result for proper page
2953+
2954+
# Test ok state template that uses user.forgotten.html
2955+
self.client.form=db_test_base.makeForm({"@template": "forgotten|item|oops|foo"})
2956+
self.client.path = 'user'
2957+
self.client.determine_context()
2958+
self.client.session_api = MockNull(_sid="1234567890")
2959+
self.assertEqual(
2960+
(self.client.classname, self.client.template, self.client.nodeid),
2961+
('user', 'forgotten|item|oops|foo', None))
2962+
self.assertEqual(self.client._ok_message, [])
2963+
2964+
result = self.client.renderContext()
2965+
print(result)
2966+
# sha1sum of classic tracker user.forgotten.template must be found
2967+
sha1sum = '<!-- SHA: f93570f95f861da40f9c45bbd2b049bb3a7c0fc5 -->'
2968+
self.assertNotEqual(-1, result.index(sha1sum))
2969+
2970+
# now set an error in the form to get error template user.item.html
2971+
self.client.form=db_test_base.makeForm({"@template": "forgotten|item|oops|foo",
2972+
"@error_message": "this is an error"})
2973+
self.client.path = 'user'
2974+
self.client.determine_context()
2975+
result = self.client.renderContext()
2976+
self.assertEqual(result, '<strong>No template file exists for templating "user" with template "item|oops|foo" (neither "user.item|oops|foo" nor "_generic.item|oops|foo")</strong>')
29442977

29452978
def testexamine_url(self):
29462979
''' test the examine_url function '''

0 commit comments

Comments
 (0)