-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIX] web: NFD UTF-8 for safari in upload file #24307
[FIX] web: NFD UTF-8 for safari in upload file #24307
Conversation
@@ -1069,16 +1070,23 @@ def upload_attachment(self, callback, model, id, ufile): | |||
var win = window.top.window; | |||
win.jQuery(win).trigger(%s, %s); | |||
</script>""" | |||
|
|||
filename = ufile.filename |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need to decode that before processing it? If in P2 this is implicitly decoded in normalize it's going to blow up in P3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From Werkzeug 0.90 code:
# On Python 3 we want to make sure the filename is always unicode.
# This might not be if the name attribute is bytes due to the
# file being opened from the bytes API.
if not PY2 and isinstance(filename, bytes):
filename = filename.decode(sys.getfilesystemencoding(),
'replace')
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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How comes we don't get the filename in NFD when it comes from Safari?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That I don't know but I'll bet on the combination of two things:
- default normalization of Safari to be NFD
- no headers specifying normalization, so werkzeug takes utf-8 and doesn't normalize
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 odoo#24307
74834b6
to
cd6150f
Compare
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
Description of the issue/feature this PR addresses:
Current behavior before PR:
Desired behavior after PR is merged:
--
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr