From 110bf158f68cc3066dc8cd1f6e47b1dd04ae7fac Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 18 Aug 2017 11:18:50 +0200 Subject: [PATCH] [FIX] website_sale_digital: special character in filename MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Create a product with attachment, and name the attachment 'テスト' - Purchase the product, make a payment, validate and pay the invoice - Go to My Orders under My Account, open the order, and try to download the file 'テスト'. An error 500 is raised due to a UnicodeEncodeError. ``` File "/home/nim/src/odoo/addons/website_sale_digital/controllers/main.py", line 104, in download_attachment return http.send_file(data, filename=attachment['name'], as_attachment=True) File "/home/nim/src/odoo/odoo/http.py", line 1595, in send_file headers.add('Content-Disposition', 'attachment', filename=filename) File "/usr/lib/python2.7/dist-packages/werkzeug/datastructures.py", line 1093, in add _value = _options_header_vkw(_value, kw) File "/usr/lib/python2.7/dist-packages/werkzeug/datastructures.py", line 830, in _options_header_vkw for k, v in kw.items())) File "/usr/lib/python2.7/dist-packages/werkzeug/http.py", line 212, in dump_options_header segments.append('%s=%s' % (key, quote_header_value(value))) File "/usr/lib/python2.7/dist-packages/werkzeug/http.py", line 165, in quote_header_value value = str(value) UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128) ``` opw-766568 --- addons/website_sale_digital/controllers/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/website_sale_digital/controllers/main.py b/addons/website_sale_digital/controllers/main.py index b633596a0bf..7977b44bac8 100644 --- a/addons/website_sale_digital/controllers/main.py +++ b/addons/website_sale_digital/controllers/main.py @@ -101,6 +101,6 @@ class WebsiteSaleDigital(website_account): return request.not_found() elif attachment["datas"]: data = StringIO(base64.standard_b64decode(attachment["datas"])) - return http.send_file(data, filename=attachment['name'], as_attachment=True) + return http.send_file(data, filename=attachment['name'].encode('utf-8'), as_attachment=True) else: return request.not_found()