mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-07 08:58:38 +00:00
[#3070] Fix httpdownloader error with missing content-disposition filename
The parsing of the content-disposition in httpdownloader was not able to handle missing parameters e.g. "Content-Disposition: attachment" and would result in an IndexError. Added a test for this use-case. Fixed the issue using the cgi.parse_header to extract the parameters.
This commit is contained in:
parent
396417bcd0
commit
ffb8d9f8c3
1 changed files with 16 additions and 12 deletions
|
@ -38,6 +38,7 @@ from twisted.python.failure import Failure
|
|||
from twisted.internet import reactor
|
||||
from deluge.log import setupLogger, LOG as log
|
||||
from common import get_version
|
||||
import cgi
|
||||
import os.path
|
||||
import zlib
|
||||
|
||||
|
@ -86,7 +87,10 @@ class HTTPDownloader(client.HTTPDownloader):
|
|||
self.decoder = zlib.decompressobj(zlib.MAX_WBITS + 32)
|
||||
|
||||
if "content-disposition" in headers and not self.force_filename:
|
||||
new_file_name = str(headers["content-disposition"][0]).split(";")[1].split("=")[1]
|
||||
content_disp = str(headers["content-disposition"][0])
|
||||
content_disp_params = cgi.parse_header(content_disp)[1]
|
||||
if "filename" in content_disp_params:
|
||||
new_file_name = content_disp_params["filename"]
|
||||
new_file_name = sanitise_filename(new_file_name)
|
||||
new_file_name = os.path.join(os.path.split(self.fileName)[0], new_file_name)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue