fix #591 invalid local filename when content-disposition invalid extension
1. fix download to remove query string from attachment name can cause regressions when filename contains query before extension or other strange characters because we parse as url an intended filename 2. fix episode.local_filename() to always sanitize the extension
This commit is contained in:
parent
0eb2756957
commit
4400f5bf16
|
@ -821,7 +821,10 @@ class DownloadTask(object):
|
|||
# an empty filename, resulting in an empty string here (bug 1440)
|
||||
if disposition_filename is not None and disposition_filename != '':
|
||||
# The server specifies a download filename - try to use it
|
||||
disposition_filename = os.path.basename(disposition_filename)
|
||||
# filename_from_url to remove query string; see #591
|
||||
fn, ext = util.filename_from_url(disposition_filename)
|
||||
logger.debug("converting disposition filename '%s' to local filename '%s%s'", disposition_filename, fn, ext)
|
||||
disposition_filename = fn + ext
|
||||
self.filename = self.__episode.local_filename(create=True,
|
||||
force_update=True, template=disposition_filename)
|
||||
new_mimetype, encoding = mimetypes.guess_type(self.filename)
|
||||
|
|
|
@ -471,6 +471,8 @@ class PodcastEpisode(PodcastModelObject):
|
|||
self.channel.url, self.url)
|
||||
fn_template = hashlib.md5(self.url.encode('utf-8')).hexdigest()
|
||||
|
||||
# Also sanitize ext (see #591 where ext=.mp3?dest-id=754182)
|
||||
ext = '.' + util.sanitize_filename(ext, self.MAX_FILENAME_LENGTH - len(fn_template) - 1)
|
||||
# Find a unique filename for this episode
|
||||
wanted_filename = self.find_unique_file_name(fn_template, ext)
|
||||
|
||||
|
|
Loading…
Reference in New Issue