summaryrefslogtreecommitdiff
path: root/addons/web
diff options
context:
space:
mode:
authorLucas Perais (lpe) <lpe@odoo.com>2018-04-18 17:49:26 +0200
committerLucas Perais (lpe) <lpe@odoo.com>2018-04-23 09:00:11 +0200
commitcd6150fe9e63d7785f140ea1e2b3090bb1a2e10b (patch)
tree381bcde7835fb779546b85a9767023df0f35b9e9 /addons/web
parentb61aad2f6b7a0b1fa5c4a2dad941a350f2c03236 (diff)
[FIX] web: NFD UTF-8 for safari in upload file
Before this commit, when uploading a file as attachment in Safari, The file icon kept on showing 'downloading' whereas the request was successful This was because the return from the server had a different UTF-8 norm than Safari After this commit, it works well OPW 1836545 closes #24307
Diffstat (limited to 'addons/web')
-rw-r--r--addons/web/controllers/main.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py
index d8cb0e6a36f..a1ead7e5d1a 100644
--- a/addons/web/controllers/main.py
+++ b/addons/web/controllers/main.py
@@ -19,6 +19,7 @@ import time
import zlib
from xml.etree import ElementTree
from cStringIO import StringIO
+import unicodedata
import babel.messages.pofile
import werkzeug.utils
@@ -1069,16 +1070,23 @@ class Binary(http.Controller):
var win = window.top.window;
win.jQuery(win).trigger(%s, %s);
</script>"""
+
+ filename = ufile.filename
+ if request.httprequest.user_agent.browser == 'safari':
+ # Safari sends NFD UTF-8 (where é is composed by 'e' and [accent])
+ # we need to send it the same stuff, otherwise it'll fail
+ filename = unicodedata.normalize('NFD', ufile.filename).encode('UTF-8')
+
try:
attachment_id = Model.create({
- 'name': ufile.filename,
+ 'name': filename,
'datas': base64.encodestring(ufile.read()),
- 'datas_fname': ufile.filename,
+ 'datas_fname': filename,
'res_model': model,
'res_id': int(id)
}, request.context)
args = {
- 'filename': ufile.filename,
+ 'filename': filename,
'mimetype': ufile.content_type,
'id': attachment_id
}