Skip to content
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

Merged
merged 1 commit into from
Apr 23, 2018

Conversation

kebeclibre
Copy link
Contributor

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

@@ -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
Copy link
Collaborator

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.

Copy link
Contributor Author

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')
Copy link
Collaborator

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?

Copy link
Contributor Author

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

@C3POdoo C3POdoo added the OE the report is linked to a support ticket (opw-...) label Apr 20, 2018
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
@kebeclibre kebeclibre force-pushed the 9.0-safari-diacritics-attach-lpe branch from 74834b6 to cd6150f Compare April 23, 2018 07:00
@kebeclibre kebeclibre merged commit cd6150f into odoo:9.0 Apr 23, 2018
@xmo-odoo xmo-odoo deleted the 9.0-safari-diacritics-attach-lpe branch November 20, 2019 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OE the report is linked to a support ticket (opw-...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants