[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:
Goffin Simon 2015-05-13 11:20:41 +02:00 committed by Martin Trigaux
parent acd61f8f0e
commit c435b8438e
1 changed files with 4 additions and 4 deletions

View File

@ -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