Skip to content

Commit d3549c4

Browse files
author
Richard Jones
committed
fixes to CGI form handling (NEEDS BACKPORTING TO 0.5)
1 parent c6dc789 commit d3549c4

File tree

3 files changed

+98
-9
lines changed

3 files changed

+98
-9
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ are given with the most recent entry first.
1313
request. It is greatly improves web interface performance, especially
1414
on trackers under high load
1515
- fix StringHTMLProperty hyperlinking
16+
- added mysql backend
17+
- fixes to CGI form handling (NEEDS BACKPORTING TO 0.5)
18+
1619

1720
2003-??-?? 0.5.5
1821
- fixed rdbms searching by ID (sf bug 666615)

roundup/cgi/client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: client.py,v 1.67 2003-01-13 22:14:00 kedder Exp $
1+
# $Id: client.py,v 1.68 2003-01-14 22:21:35 richard Exp $
22

33
__doc__ = """
44
WWW request handler (also used in the stand-alone server).
@@ -1252,8 +1252,6 @@ def parsePropsFromForm(db, cl, form, nodeid=0, num_re=re.compile('^\d+$')):
12521252
value = value.value.strip()
12531253

12541254
if isinstance(proptype, hyperdb.String):
1255-
if not value:
1256-
continue
12571255
# fix the CRLF/CR -> LF stuff
12581256
value = fixNewlines(value)
12591257
elif isinstance(proptype, hyperdb.Password):
@@ -1369,10 +1367,17 @@ def parsePropsFromForm(db, cl, form, nodeid=0, num_re=re.compile('^\d+$')):
13691367
if not properties.has_key(propname):
13701368
raise
13711369

1370+
# existing may be None, which won't equate to empty strings
1371+
if not existing and not value:
1372+
continue
1373+
13721374
# if changed, set it
13731375
if value != existing:
13741376
props[propname] = value
13751377
else:
1378+
# don't bother setting empty/unset values
1379+
if not value:
1380+
continue
13761381
props[propname] = value
13771382

13781383
# see if all the required properties have been supplied

test/test_cgi.py

Lines changed: 87 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
# but WITHOUT ANY WARRANTY; without even the implied warranty of
99
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1010
#
11-
# $Id: test_cgi.py,v 1.1 2003-01-14 06:15:58 richard Exp $
11+
# $Id: test_cgi.py,v 1.2 2003-01-14 22:21:35 richard Exp $
1212

1313
import unittest, os, shutil, errno, sys, difflib, cgi
1414

1515
from roundup.cgi import client
16-
from roundup import init, instance
16+
from roundup import init, instance, password
1717

1818
def makeForm(args):
1919
form = cgi.FieldStorage()
2020
for k,v in args.items():
2121
if type(v) is type([]):
22-
form.list.append([cgi.MiniFieldStorage(k, x) for x in v])
22+
[form.list.append(cgi.MiniFieldStorage(k, x)) for x in v]
2323
else:
2424
form.list.append(cgi.MiniFieldStorage(k, v))
2525
return form
@@ -50,14 +50,95 @@ def tearDown(self):
5050
except OSError, error:
5151
if error.errno not in (errno.ENOENT, errno.ESRCH): raise
5252

53-
def testParseNothing(self):
54-
client.parsePropsFromForm(self.db, self.db.issue, makeForm({}))
53+
#
54+
# Empty form
55+
#
56+
def testNothing(self):
57+
self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
58+
makeForm({})), {})
5559

56-
def testParseNothingWithRequired(self):
60+
def testNothingWithRequired(self):
5761
form = makeForm({':required': 'title'})
5862
self.assertRaises(ValueError, client.parsePropsFromForm, self.db,
5963
self.db.issue, form)
6064

65+
#
66+
# String
67+
#
68+
def testEmptyString(self):
69+
self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
70+
makeForm({'title': ''})), {})
71+
self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
72+
makeForm({'title': ' '})), {})
73+
74+
def testSetString(self):
75+
self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
76+
makeForm({'title': 'foo'})), {'title': 'foo'})
77+
self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
78+
makeForm({'title': 'a\r\nb\r\n'})), {'title': 'a\nb'})
79+
80+
def testEmptyStringSet(self):
81+
nodeid = self.db.issue.create(title='foo')
82+
self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
83+
makeForm({'title': ''}), nodeid), {'title': ''})
84+
nodeid = self.db.issue.create(title='foo')
85+
self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
86+
makeForm({'title': ' '}), nodeid), {'title': ''})
87+
88+
#
89+
# Multilink
90+
#
91+
def testEmptyMultilink(self):
92+
self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
93+
makeForm({'nosy': ''})), {})
94+
self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
95+
makeForm({'nosy': ' '})), {})
96+
97+
def testSetMultilink(self):
98+
self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
99+
makeForm({'nosy': '1'})), {'nosy': ['1']})
100+
self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
101+
makeForm({'nosy': ['1','2']})), {'nosy': ['1','2']})
102+
self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
103+
makeForm({'nosy': '1,2'})), {'nosy': ['1','2']})
104+
105+
def testEmptyMultilinkSet(self):
106+
nodeid = self.db.issue.create(nosy=['1','2'])
107+
self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
108+
makeForm({'nosy': ''}), nodeid), {'nosy': []})
109+
nodeid = self.db.issue.create(nosy=['1','2'])
110+
self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
111+
makeForm({'nosy': ' '}), nodeid), {'nosy': []})
112+
113+
#
114+
# Password
115+
#
116+
def testEmptyPassword(self):
117+
self.assertEqual(client.parsePropsFromForm(self.db, self.db.user,
118+
makeForm({'password': ''})), {})
119+
self.assertEqual(client.parsePropsFromForm(self.db, self.db.user,
120+
makeForm({'password': ''})), {})
121+
122+
def testSetPassword(self):
123+
self.assertEqual(client.parsePropsFromForm(self.db, self.db.user,
124+
makeForm({'password': 'foo', 'password:confirm': 'foo'})),
125+
{'password': 'foo'})
126+
127+
def testSetPasswordConfirmBad(self):
128+
self.assertRaises(ValueError, client.parsePropsFromForm, self.db,
129+
self.db.user, makeForm({'password': 'foo'}))
130+
self.assertRaises(ValueError, client.parsePropsFromForm, self.db,
131+
self.db.user, makeForm({'password': 'foo',
132+
'password:confirm': 'bar'}))
133+
134+
def testEmptyPasswordNOTSet(self):
135+
nodeid = self.db.user.create(username='1', password=password.Password('foo'))
136+
self.assertEqual(client.parsePropsFromForm(self.db, self.db.user,
137+
makeForm({'password': ''}), nodeid), {})
138+
nodeid = self.db.user.create(username='2', password=password.Password('foo'))
139+
self.assertEqual(client.parsePropsFromForm(self.db, self.db.user,
140+
makeForm({'password': '', 'password:confirm': ''}), nodeid), {})
141+
61142

62143
def suite():
63144
l = [unittest.makeSuite(FormTestCase),

0 commit comments

Comments
 (0)