sfneal / PyPDF3

A utility to read and write PDFs with Python
https://pythonhosted.org/PyPDF2/
Other
72 stars 15 forks source link

formatWarning can crash #11

Open farcepest opened 2 years ago

farcepest commented 2 years ago

Apparently there are cases where PyPDF3 can generate a warning, but there's no filename to be found, which raises IndexError. In my case, this is happening while running coverage, during the collection phase.

File "/usr/lib/python3.8/ast.py", line 47, in parse return compile(source, filename, mode, flags, File "/usr/lib/python3.8/warnings.py", line 109, in _showwarnmsg sw(msg.message, msg.category, msg.filename, msg.lineno, File "/opt/python/lib/python3.8/site-packages/PyPDF3/pdf.py", line 1186, in _showwarning file.write(formatWarning(message, category, filename, lineno, line)) File "/opt/python/lib/python3.8/site-packages/PyPDF3/utils.py", line 65, in formatWarning file = filename.replace("/", "\").rsplit("\", 1)[1] # find the file name IndexError: list index out of range

Python 3.8.10 (Ubuntu 20.04 LTS)