Merge lp:~gdrius/openerp-web/trunk-bugfix-1072803-giedrius into lp:openerp-web

Proposed by Giedrius Slavinskas - inovera.lt
Status: Merged
Merged at revision: 3344
Proposed branch: lp:~gdrius/openerp-web/trunk-bugfix-1072803-giedrius
Merge into: lp:openerp-web
Diff against target: 93 lines (+21/-17)
1 file modified
addons/web/controllers/main.py (+21/-17)
To merge this branch: bzr merge lp:~gdrius/openerp-web/trunk-bugfix-1072803-giedrius
Reviewer Review Type Date Requested Status
Xavier (Open ERP) (community) Approve
Nicolas Vanhoren (OpenERP) Pending
Review via email: mp+132085@code.launchpad.net

Commit message

[FIX] escape returned report filename

Description of the change

This branch fixes bug when reports cannot be printed if name contains non latin charachter.

https://bugs.launchpad.net/openerp-web/+bug/1072803

To post a comment you must log in.
Revision history for this message
Xavier (Open ERP) (xmo-deactivatedaccount) wrote :

Looks good to me, thank you. I paged fme for his opinion.

Also, would you mind extending this fix to the database download code (Database.backup controller)? It also uses a raw Content-Disposition, though it doesn't use a user-provided filename it would probably be safer.

review: Approve
3330. By Giedrius Slavinskas - inovera.lt

[FIX] escape returned database backup and exported data filenames

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/web/controllers/main.py'
2--- addons/web/controllers/main.py 2012-10-10 20:37:53 +0000
3+++ addons/web/controllers/main.py 2012-10-31 15:57:21 +0000
4@@ -575,6 +575,20 @@
5 res["children"] = kids
6 return res
7
8+
9+def content_disposition(filename, req):
10+ filename = filename.encode('utf8')
11+ escaped = urllib2.quote(filename)
12+ browser = req.httprequest.user_agent.browser
13+ version = int((req.httprequest.user_agent.version or '0').split('.')[0])
14+ if browser == 'msie' and version < 9:
15+ return "attachment; filename=%s" % escaped
16+ elif browser == 'safari':
17+ return "attachment; filename=%s" % filename
18+ else:
19+ return "attachment; filename*=UTF-8''%s" % escaped
20+
21+
22 #----------------------------------------------------------
23 # OpenERP Web web Controllers
24 #----------------------------------------------------------
25@@ -841,7 +855,7 @@
26 }
27 return req.make_response(db_dump,
28 [('Content-Type', 'application/octet-stream; charset=binary'),
29- ('Content-Disposition', 'attachment; filename="' + filename + '"')],
30+ ('Content-Disposition', content_disposition(filename, req))],
31 {'fileToken': int(token)}
32 )
33 except xmlrpclib.Fault, e:
34@@ -1520,17 +1534,6 @@
35 def placeholder(self, req):
36 addons_path = openerpweb.addons_manifest['web']['addons_path']
37 return open(os.path.join(addons_path, 'web', 'static', 'src', 'img', 'placeholder.png'), 'rb').read()
38- def content_disposition(self, filename, req):
39- filename = filename.encode('utf8')
40- escaped = urllib2.quote(filename)
41- browser = req.httprequest.user_agent.browser
42- version = int((req.httprequest.user_agent.version or '0').split('.')[0])
43- if browser == 'msie' and version < 9:
44- return "attachment; filename=%s" % escaped
45- elif browser == 'safari':
46- return "attachment; filename=%s" % filename
47- else:
48- return "attachment; filename*=UTF-8''%s" % escaped
49
50 @openerpweb.httprequest
51 def saveas(self, req, model, field, id=None, filename_field=None, **kw):
52@@ -1566,7 +1569,7 @@
53 filename = res.get(filename_field, '') or filename
54 return req.make_response(filecontent,
55 [('Content-Type', 'application/octet-stream'),
56- ('Content-Disposition', self.content_disposition(filename, req))])
57+ ('Content-Disposition', content_disposition(filename, req))])
58
59 @openerpweb.httprequest
60 def saveas_ajax(self, req, data, token):
61@@ -1596,7 +1599,7 @@
62 filename = res.get(filename_field, '') or filename
63 return req.make_response(filecontent,
64 headers=[('Content-Type', 'application/octet-stream'),
65- ('Content-Disposition', self.content_disposition(filename, req))],
66+ ('Content-Disposition', content_disposition(filename, req))],
67 cookies={'fileToken': int(token)})
68
69 @openerpweb.httprequest
70@@ -1861,7 +1864,8 @@
71
72
73 return req.make_response(self.from_data(columns_headers, import_data),
74- headers=[('Content-Disposition', 'attachment; filename="%s"' % self.filename(model)),
75+ headers=[('Content-Disposition',
76+ content_disposition(self.filename(model), req)),
77 ('Content-Type', self.content_type)],
78 cookies={'fileToken': int(token)})
79
80@@ -1997,11 +2001,11 @@
81 file_name = reports.read(res_id[0], ['name'], context)['name']
82 else:
83 file_name = action['report_name']
84+ file_name = '%s.%s' % (file_name, report_struct['format'])
85
86 return req.make_response(report,
87 headers=[
88- # maybe we should take of what characters can appear in a file name?
89- ('Content-Disposition', 'attachment; filename="%s.%s"' % (file_name, report_struct['format'])),
90+ ('Content-Disposition', content_disposition(file_name, req)),
91 ('Content-Type', report_mimetype),
92 ('Content-Length', len(report))],
93 cookies={'fileToken': int(token)})