mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Discard an empty upload_name before persisting an uploaded file (#7905)
This commit is contained in:
parent
e154f7ccb5
commit
c2bdf040aa
1
changelog.d/7905.bugfix
Normal file
1
changelog.d/7905.bugfix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fix a longstanding bug when storing a media file with an empty `upload_name`.
|
@ -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:
|
|||||||
"""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:
|
|||||||
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)
|
||||||
|
@ -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"):
|
||||||
|
Loading…
Reference in New Issue
Block a user