witten
/
luminotes
Archived
1
0
Fork 0

Tweaked controller.Files.download() to better handle filenames with weird characters.

This commit is contained in:
Dan Helfman 2008-02-24 01:01:50 +00:00
parent 9743859b41
commit dcd40eaa45
2 changed files with 3 additions and 3 deletions

View File

@ -264,7 +264,7 @@ class Files( object ):
db_file = self.__database.load( File, file_id )
cherrypy.response.headerMap[ u"Content-Type" ] = db_file.content_type
cherrypy.response.headerMap[ u"Content-Disposition" ] = u"attachment; filename=%s" % db_file.filename
cherrypy.response.headerMap[ u"Content-Disposition" ] = u'attachment; filename="%s"' % db_file.filename.replace( '"', r"\"" )
cherrypy.response.headerMap[ u"Content-Length" ] = db_file.size_bytes
def stream():

View File

@ -33,7 +33,7 @@ class Test_files( Test_controller ):
self.file_id = "22"
self.filename = "file.png"
self.new_filename = "newfile.png"
self.file_data = "foobar\x07`-=[]\;',./~!@#$%^&*()_+{}|:\"<>?" * 100
self.file_data = "foobar\x07`-=[]\;',./ ~!@#$%^&*()_+{}|:\"<>?" * 100
self.weird_filename = self.file_data + ".png"
self.content_type = "image/png"
self.upload_thread = None
@ -139,7 +139,7 @@ class Test_files( Test_controller ):
headers = result[ u"headers" ]
assert headers
assert headers[ u"Content-Type" ] == self.content_type
assert headers[ u"Content-Disposition" ] == u"attachment; filename=%s" % self.filename
assert headers[ u"Content-Disposition" ] == u'attachment; filename="%s"' % self.filename
gen = result[ u"body" ]
assert isinstance( gen, types.GeneratorType )