From: richard Date: Tue, 14 Jan 2003 22:21:35 +0000 (+0000) Subject: fixes to CGI form handling (NEEDS BACKPORTING TO 0.5) X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=645af65faad235c04f3f4f258d07654945a02de4;p=roundup.git fixes to CGI form handling (NEEDS BACKPORTING TO 0.5) git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1456 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/CHANGES.txt b/CHANGES.txt index ab49ca5..d52a001 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -13,6 +13,9 @@ are given with the most recent entry first. request. It is greatly improves web interface performance, especially on trackers under high load - fix StringHTMLProperty hyperlinking +- added mysql backend +- fixes to CGI form handling (NEEDS BACKPORTING TO 0.5) + 2003-??-?? 0.5.5 - fixed rdbms searching by ID (sf bug 666615) diff --git a/roundup/cgi/client.py b/roundup/cgi/client.py index b2ee207..b4a310f 100644 --- a/roundup/cgi/client.py +++ b/roundup/cgi/client.py @@ -1,4 +1,4 @@ -# $Id: client.py,v 1.67 2003-01-13 22:14:00 kedder Exp $ +# $Id: client.py,v 1.68 2003-01-14 22:21:35 richard Exp $ __doc__ = """ 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+$')): value = value.value.strip() if isinstance(proptype, hyperdb.String): - if not value: - continue # fix the CRLF/CR -> LF stuff value = fixNewlines(value) elif isinstance(proptype, hyperdb.Password): @@ -1369,10 +1367,17 @@ def parsePropsFromForm(db, cl, form, nodeid=0, num_re=re.compile('^\d+$')): if not properties.has_key(propname): raise + # existing may be None, which won't equate to empty strings + if not existing and not value: + continue + # if changed, set it if value != existing: props[propname] = value else: + # don't bother setting empty/unset values + if not value: + continue props[propname] = value # see if all the required properties have been supplied diff --git a/test/test_cgi.py b/test/test_cgi.py index 857d41d..d9887a2 100644 --- a/test/test_cgi.py +++ b/test/test_cgi.py @@ -8,18 +8,18 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # -# $Id: test_cgi.py,v 1.1 2003-01-14 06:15:58 richard Exp $ +# $Id: test_cgi.py,v 1.2 2003-01-14 22:21:35 richard Exp $ import unittest, os, shutil, errno, sys, difflib, cgi from roundup.cgi import client -from roundup import init, instance +from roundup import init, instance, password def makeForm(args): form = cgi.FieldStorage() for k,v in args.items(): if type(v) is type([]): - form.list.append([cgi.MiniFieldStorage(k, x) for x in v]) + [form.list.append(cgi.MiniFieldStorage(k, x)) for x in v] else: form.list.append(cgi.MiniFieldStorage(k, v)) return form @@ -50,14 +50,95 @@ class FormTestCase(unittest.TestCase): except OSError, error: if error.errno not in (errno.ENOENT, errno.ESRCH): raise - def testParseNothing(self): - client.parsePropsFromForm(self.db, self.db.issue, makeForm({})) + # + # Empty form + # + def testNothing(self): + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, + makeForm({})), {}) - def testParseNothingWithRequired(self): + def testNothingWithRequired(self): form = makeForm({':required': 'title'}) self.assertRaises(ValueError, client.parsePropsFromForm, self.db, self.db.issue, form) + # + # String + # + def testEmptyString(self): + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, + makeForm({'title': ''})), {}) + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, + makeForm({'title': ' '})), {}) + + def testSetString(self): + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, + makeForm({'title': 'foo'})), {'title': 'foo'}) + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, + makeForm({'title': 'a\r\nb\r\n'})), {'title': 'a\nb'}) + + def testEmptyStringSet(self): + nodeid = self.db.issue.create(title='foo') + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, + makeForm({'title': ''}), nodeid), {'title': ''}) + nodeid = self.db.issue.create(title='foo') + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, + makeForm({'title': ' '}), nodeid), {'title': ''}) + + # + # Multilink + # + def testEmptyMultilink(self): + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, + makeForm({'nosy': ''})), {}) + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, + makeForm({'nosy': ' '})), {}) + + def testSetMultilink(self): + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, + makeForm({'nosy': '1'})), {'nosy': ['1']}) + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, + makeForm({'nosy': ['1','2']})), {'nosy': ['1','2']}) + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, + makeForm({'nosy': '1,2'})), {'nosy': ['1','2']}) + + def testEmptyMultilinkSet(self): + nodeid = self.db.issue.create(nosy=['1','2']) + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, + makeForm({'nosy': ''}), nodeid), {'nosy': []}) + nodeid = self.db.issue.create(nosy=['1','2']) + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, + makeForm({'nosy': ' '}), nodeid), {'nosy': []}) + + # + # Password + # + def testEmptyPassword(self): + self.assertEqual(client.parsePropsFromForm(self.db, self.db.user, + makeForm({'password': ''})), {}) + self.assertEqual(client.parsePropsFromForm(self.db, self.db.user, + makeForm({'password': ''})), {}) + + def testSetPassword(self): + self.assertEqual(client.parsePropsFromForm(self.db, self.db.user, + makeForm({'password': 'foo', 'password:confirm': 'foo'})), + {'password': 'foo'}) + + def testSetPasswordConfirmBad(self): + self.assertRaises(ValueError, client.parsePropsFromForm, self.db, + self.db.user, makeForm({'password': 'foo'})) + self.assertRaises(ValueError, client.parsePropsFromForm, self.db, + self.db.user, makeForm({'password': 'foo', + 'password:confirm': 'bar'})) + + def testEmptyPasswordNOTSet(self): + nodeid = self.db.user.create(username='1', password=password.Password('foo')) + self.assertEqual(client.parsePropsFromForm(self.db, self.db.user, + makeForm({'password': ''}), nodeid), {}) + nodeid = self.db.user.create(username='2', password=password.Password('foo')) + self.assertEqual(client.parsePropsFromForm(self.db, self.db.user, + makeForm({'password': '', 'password:confirm': ''}), nodeid), {}) + def suite(): l = [unittest.makeSuite(FormTestCase),