Mercurial > p > roundup > code
comparison roundup/cgi/form_parser.py @ 5522:c5c33e62da39
Fix absent file uploads with Python 3.
If a form has a file upload input control for a Link to a FileClass
class, but no file is uploaded, browsers submit this as an upload with
empty filename and file contents. This then goes through the Roundup
code:
# value might be a single file upload
if not getattr(value, 'filename', None):
value = value.value.strip()
which results in value holding those empty file contents.
With Python 2, the code
elif value == '':
# other types should be None'd if there's no value
value = None
then results in value being set to None, meaning no file node gets
created. With Python 3, however, value is b'' at this point and so
the code ends up creating a file node with empty content. Thus, this
patch fixes this by also checking for b'' there.
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Sat, 01 Sep 2018 18:29:16 +0000 |
| parents | 3fa026621f69 |
| children | 936275dfe1fa |
comparison
equal
deleted
inserted
replaced
| 5521:d7e6b1c86ee8 | 5522:c5c33e62da39 |
|---|---|
| 467 value = existing | 467 value = existing |
| 468 # Sort the value in the same order used by | 468 # Sort the value in the same order used by |
| 469 # Multilink.from_raw. | 469 # Multilink.from_raw. |
| 470 value.sort(key=int) | 470 value.sort(key=int) |
| 471 | 471 |
| 472 elif value == '': | 472 elif value == '' or value == b'': |
| 473 # other types should be None'd if there's no value | 473 # other types should be None'd if there's no value |
| 474 value = None | 474 value = None |
| 475 else: | 475 else: |
| 476 # handle all other types | 476 # handle all other types |
| 477 try: | 477 try: |
