Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
5a9e0c36
Commit
5a9e0c36
authored
9 years ago
by
Mark Haines
Browse files
Options
Downloads
Patches
Plain Diff
Handle unicode filenames given when downloading or received over federation
parent
e85c7873
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/rest/media/v1/base_resource.py
+21
-5
21 additions, 5 deletions
synapse/rest/media/v1/base_resource.py
with
21 additions
and
5 deletions
synapse/rest/media/v1/base_resource.py
+
21
−
5
View file @
5a9e0c36
...
@@ -34,6 +34,7 @@ import os
...
@@ -34,6 +34,7 @@ import os
import
cgi
import
cgi
import
logging
import
logging
import
urllib
import
urllib
import
urlparse
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -43,10 +44,13 @@ def parse_media_id(request):
...
@@ -43,10 +44,13 @@ def parse_media_id(request):
# This allows users to append e.g. /test.png to the URL. Useful for
# This allows users to append e.g. /test.png to the URL. Useful for
# clients that parse the URL to see content type.
# clients that parse the URL to see content type.
server_name
,
media_id
=
request
.
postpath
[:
2
]
server_name
,
media_id
=
request
.
postpath
[:
2
]
if
len
(
request
.
postpath
)
>
2
and
is_ascii
(
request
.
postpath
[
-
1
]):
file_name
=
None
return
server_name
,
media_id
,
request
.
postpath
[
-
1
]
if
len
(
request
.
postpath
)
>
2
:
else
:
try
:
return
server_name
,
media_id
,
None
file_name
=
urlparse
.
unquote
(
request
.
postpath
[
-
1
]).
decode
(
"
utf-8
"
)
except
UnicodeDecodeError
:
pass
return
server_name
,
media_id
,
file_name
except
:
except
:
raise
SynapseError
(
raise
SynapseError
(
404
,
404
,
...
@@ -144,6 +148,16 @@ class BaseMediaResource(Resource):
...
@@ -144,6 +148,16 @@ class BaseMediaResource(Resource):
upload_name
=
params
.
get
(
"
filename
"
,
None
)
upload_name
=
params
.
get
(
"
filename
"
,
None
)
if
upload_name
and
not
is_ascii
(
upload_name
):
if
upload_name
and
not
is_ascii
(
upload_name
):
upload_name
=
None
upload_name
=
None
else
:
upload_name_utf8
=
params
.
get
(
"
filename*
"
,
None
)
if
upload_name_utf8
.
lower
().
startswith
(
"
utf-8
''"
):
upload_name
=
upload_name_utf8
[
7
:]
if
upload_name
:
upload_name
=
urlparse
.
unquote
(
upload_name
)
try
:
upload_name
=
upload_name
.
decode
(
"
utf-8
"
);
except
UnicodeDecodeError
:
upload_name
=
None
else
:
else
:
upload_name
=
None
upload_name
=
None
...
@@ -185,7 +199,9 @@ class BaseMediaResource(Resource):
...
@@ -185,7 +199,9 @@ class BaseMediaResource(Resource):
if
is_ascii
(
upload_name
):
if
is_ascii
(
upload_name
):
request
.
setHeader
(
request
.
setHeader
(
b
"
Content-Disposition
"
,
b
"
Content-Disposition
"
,
b
"
inline; filename=%s
"
%
(
upload_name
.
encode
(
"
utf-8
"
),),
b
"
inline; filename=%s
"
%
(
urllib
.
quote
(
upload_name
.
encode
(
"
utf-8
"
)),
),
)
)
else
:
else
:
request
.
setHeader
(
request
.
setHeader
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment