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
c2bdf040
Unverified
Commit
c2bdf040
authored
4 years ago
by
Will Hunt
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Discard an empty upload_name before persisting an uploaded file (#7905)
parent
e154f7cc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changelog.d/7905.bugfix
+1
-0
1 addition, 0 deletions
changelog.d/7905.bugfix
synapse/rest/media/v1/media_repository.py
+4
-3
4 additions, 3 deletions
synapse/rest/media/v1/media_repository.py
synapse/rest/media/v1/upload_resource.py
+4
-0
4 additions, 0 deletions
synapse/rest/media/v1/upload_resource.py
with
9 additions
and
3 deletions
changelog.d/7905.bugfix
0 → 100644
+
1
−
0
View file @
c2bdf040
Fix a longstanding bug when storing a media file with an empty `upload_name`.
This diff is collapsed.
Click to expand it.
synapse/rest/media/v1/media_repository.py
+
4
−
3
View file @
c2bdf040
...
@@ -139,7 +139,7 @@ class MediaRepository:
...
@@ -139,7 +139,7 @@ class MediaRepository:
async
def
create_content
(
async
def
create_content
(
self
,
self
,
media_type
:
str
,
media_type
:
str
,
upload_name
:
str
,
upload_name
:
Optional
[
str
]
,
content
:
IO
,
content
:
IO
,
content_length
:
int
,
content_length
:
int
,
auth_user
:
str
,
auth_user
:
str
,
...
@@ -147,8 +147,8 @@ class MediaRepository:
...
@@ -147,8 +147,8 @@ class MediaRepository:
"""
Store uploaded content for a local user and return the mxc URL
"""
Store uploaded content for a local user and return the mxc URL
Args:
Args:
media_type: The content type of the file
media_type: The content type of the file
.
upload_name: The name of the file
upload_name: The name of the file
, if provided.
content: A file like object that is the content to store
content: A file like object that is the content to store
content_length: The length of the content
content_length: The length of the content
auth_user: The user_id of the uploader
auth_user: The user_id of the uploader
...
@@ -156,6 +156,7 @@ class MediaRepository:
...
@@ -156,6 +156,7 @@ class MediaRepository:
Returns:
Returns:
The mxc url of the stored content
The mxc url of the stored content
"""
"""
media_id
=
random_string
(
24
)
media_id
=
random_string
(
24
)
file_info
=
FileInfo
(
server_name
=
None
,
file_id
=
media_id
)
file_info
=
FileInfo
(
server_name
=
None
,
file_id
=
media_id
)
...
...
This diff is collapsed.
Click to expand it.
synapse/rest/media/v1/upload_resource.py
+
4
−
0
View file @
c2bdf040
...
@@ -63,6 +63,10 @@ class UploadResource(DirectServeJsonResource):
...
@@ -63,6 +63,10 @@ class UploadResource(DirectServeJsonResource):
msg
=
"
Invalid UTF-8 filename parameter: %r
"
%
(
upload_name
),
code
=
400
msg
=
"
Invalid UTF-8 filename parameter: %r
"
%
(
upload_name
),
code
=
400
)
)
# If the name is falsey (e.g. an empty byte string) ensure it is None.
else
:
upload_name
=
None
headers
=
request
.
requestHeaders
headers
=
request
.
requestHeaders
if
headers
.
hasHeader
(
b
"
Content-Type
"
):
if
headers
.
hasHeader
(
b
"
Content-Type
"
):
...
...
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