Mercurial > p > roundup > code
view test/cmp_helper.py @ 8268:05d8806b25ad
fix: issue2551387 - TypeError: not indexable.
Fix crash due to uninitialized list element on a (Mini)FieldStorage
when unexpected input is posted via wsgi. This doesn't happen when
running roundup-server. It might happen under other front ends.
Moved the code that sets '.list = [] if .list == None' to the main
flow. Added an exception hander that logs the value of self.form if
self.form.list raises an AttributeError. This exception should never
happen if I understand the code correctly (but I probably don't).
Fixed a number of test cases that were broken because I was calling
Client and passing '[]' rather than a cgi.formStorage object.
Added test cases:
create a FileStorage (self.form) with .list = None.
check AttributeError exception and verify logging.
Problem reported and debugged by Christof Meerwald.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 12 Jan 2025 12:34:52 -0500 |
| parents | 19bd4b413ed6 |
| children |
line wrap: on
line source
class StringFragmentCmpHelper: def compareStringFragments(self, s, fragments): """Compare a string agains a list of fragments where a tuple denotes a set of alternatives """ pos = 0 for frag in fragments: if type(frag) != tuple: self.assertEqual(s[pos:pos + len(frag)], frag) pos += len(frag) else: found = False for alt in frag: if s[pos:pos + len(alt)] == alt: pos += len(alt) found = True break if not found: l = max(map(len, frag)) raise AssertionError('%s != %s' % (repr(s[pos:pos + l]), str(frag))) self.assertEqual(s[pos:], '')
