Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Websites UFRPE
Django Private Storage
Commits
675651ac
Unverified
Commit
675651ac
authored
May 08, 2018
by
Diederik van der Boor
Browse files
Support UTF8 encoded attachments in MSIE
parent
959efde7
Changes
2
Show whitespace changes
Inline
Side-by-side
private_storage/tests/test_views.py
View file @
675651ac
...
...
@@ -90,7 +90,7 @@ class ViewTests(PrivateFileTestCase):
for
user_agent
,
expect_header
in
[
(
'Firefox'
,
"attachment; filename*=UTF-8''Heiz%C3%B6lr%C3%BCcksto%C3%9Fabd%C3%A4mpfung.txt"
),
(
'WebKit'
,
'attachment; filename=Heiz
\xc3\xb6
lr
\xc3\xbc
cksto
\xc3\x9f
abd
\xc3\xa4
mpfung.txt'
),
(
'MSIE'
,
'attachment; '
),
(
'MSIE'
,
'attachment;
filename=Heiz%C3%B6lr%C3%BCcksto%C3%9Fabd%C3%A4mpfung.txt
'
),
]:
request
=
RequestFactory
().
get
(
'/cust1/file/'
)
...
...
private_storage/views.py
View file @
675651ac
...
...
@@ -102,8 +102,8 @@ class PrivateStorageView(View):
response
=
self
.
server_class
().
serve
(
private_file
)
if
self
.
content_disposition
:
# Python 3 doesn't support b'..'.format(),
and % formatting
#
was added
in 3.
4: #
https://bugs.python.org/issue3982
#
Join syntax works in all Python versions.
Python 3 doesn't support b'..'.format(),
#
and % formatting was added for bytes
in 3.
5:
https://bugs.python.org/issue3982
filename
=
self
.
get_content_disposition_filename
(
private_file
)
response
[
'Content-Disposition'
]
=
b
'; '
.
join
([
self
.
content_disposition
.
encode
(),
self
.
_encode_filename_header
(
filename
)
...
...
@@ -125,11 +125,14 @@ class PrivateStorageView(View):
user_agent
=
self
.
request
.
META
.
get
(
'HTTP_USER_AGENT'
,
None
)
if
'WebKit'
in
user_agent
:
# Support available for UTF-8 encoded strings.
# This also matches Edgee.
return
u
'filename={}'
.
format
(
filename
).
encode
(
"utf-8"
)
elif
'MSIE'
in
user_agent
:
# IE does not support internationalized filename at all.
# It can only recognize internationalized URL, so we should perform a trick via URL names.
return
b
''
# IE does not support RFC2231 for internationalized headers, but somehow
# percent-decodes it so this can be used instead. Note that using the word
# "attachment" anywhere in the filename overrides an inline content-disposition.
url_encoded
=
quote
(
filename
.
encode
(
"utf-8"
)).
replace
(
'attachment'
,
"a%74tachment"
)
return
"filename={}"
.
format
(
url_encoded
).
encode
(
"utf-8"
)
else
:
# For others like Firefox, we follow RFC2231 (encoding extension in HTTP headers).
rfc2231_filename
=
quote
(
filename
.
encode
(
"utf-8"
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment