This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Odd behavior with "file" and "filename" attributes in cgi.FieldStorage
Type: Stage:
Components: Versions: Python 3.4
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: deadpixi, ethan.furman
Priority: normal Keywords:

Created on 2015-04-14 16:48 by deadpixi, last changed 2022-04-11 14:58 by admin.

Messages (1)
msg240942 - (view) Author: Rob King (deadpixi) Date: 2015-04-14 16:48
Hello, everyone.

I've noticed an issue that could be just a documentation inaccuracy or a genuine, minor bug in cgi.FieldStorage.

The documentation for the module states:

"You can test for an uploaded file by testing either the filename attribute or the file attribute."

However, I've noticed that on a form submission that includes both a file field and a normal form field, *all* of the members of the form have a non-None "file" attribute, while only the actual uploaded file has a non-None "filename" attribute.

This would appear to be caused by the cgi module's use of MiniFieldStorage for in some situations, and FieldStorage in others. The FieldStorage class (if I'm reading the code correctly) would appear to always have a non-None "file" attribute but may have a None "filename" attribute.

This makes the documentation for the module unclear, as testing for a non-None "file" attribute will always return True in cases of FieldStorage, even if the particular field is not actually a file.

I would suggest modifying the documentation to say something like:

"You can test for an uploaded file by testing the filename attribute."

Please let me know if I'm missing something, that's always also a possibility. :)
History
Date User Action Args
2022-04-11 14:58:15adminsetgithub: 68138
2021-11-27 14:41:00iritkatrielsetnosy: + ethan.furman
2015-04-14 16:48:15deadpixicreate