[FIX] web: With safari, UnicodeDecodeError
The headers returned by content_disposition must be either in Unicode or in ASCII. The encode function expects a Unicode or ASCII string. The quote function from urllib2 expects a UTF-8 string and retruns a ASCII string. opw:634205 Fixes #6160, #6557
This commit is contained in:
parent
acd61f8f0e
commit
c435b8438e
|
@ -32,7 +32,7 @@ except ImportError:
|
|||
import openerp
|
||||
import openerp.modules.registry
|
||||
from openerp.tools.translate import _
|
||||
from openerp.tools import config
|
||||
from openerp.tools import config, ustr
|
||||
|
||||
from .. import http
|
||||
openerpweb = http
|
||||
|
@ -520,14 +520,14 @@ def xml2json_from_elementtree(el, preserve_whitespaces=False):
|
|||
return res
|
||||
|
||||
def content_disposition(filename, req):
|
||||
filename = filename.encode('utf8')
|
||||
escaped = urllib2.quote(filename)
|
||||
filename = ustr(filename)
|
||||
escaped = urllib2.quote(filename.encode('utf8'))
|
||||
browser = req.httprequest.user_agent.browser
|
||||
version = int((req.httprequest.user_agent.version or '0').split('.')[0])
|
||||
if browser == 'msie' and version < 9:
|
||||
return "attachment; filename=%s" % escaped
|
||||
elif browser == 'safari':
|
||||
return "attachment; filename=\"%s\"" % filename
|
||||
return u"attachment; filename=%s" % filename
|
||||
else:
|
||||
return "attachment; filename*=UTF-8''%s" % escaped
|
||||
|
||||
|
|
Loading…
Reference in New Issue