mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-09-06 21:11:57 +00:00
Allow non-ascii filenames for attachments
This commit is contained in:
parent
efdaa5dd55
commit
e85c7873dc
@ -33,6 +33,7 @@ import os
|
|||||||
|
|
||||||
import cgi
|
import cgi
|
||||||
import logging
|
import logging
|
||||||
|
import urllib
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -181,10 +182,18 @@ class BaseMediaResource(Resource):
|
|||||||
if os.path.isfile(file_path):
|
if os.path.isfile(file_path):
|
||||||
request.setHeader(b"Content-Type", media_type.encode("UTF-8"))
|
request.setHeader(b"Content-Type", media_type.encode("UTF-8"))
|
||||||
if upload_name:
|
if upload_name:
|
||||||
request.setHeader(
|
if is_ascii(upload_name):
|
||||||
b"Content-Disposition",
|
request.setHeader(
|
||||||
b"inline; filename=%s" % (upload_name.encode("utf-8"),),
|
b"Content-Disposition",
|
||||||
)
|
b"inline; filename=%s" % (upload_name.encode("utf-8"),),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
request.setHeader(
|
||||||
|
b"Content-Disposition",
|
||||||
|
b"inline; filename*=utf-8''%s" % (
|
||||||
|
urllib.quote(upload_name.encode("utf-8")),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
# cache for at least a day.
|
# cache for at least a day.
|
||||||
# XXX: we might want to turn this off for data we don't want to
|
# XXX: we might want to turn this off for data we don't want to
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
from synapse.http.server import respond_with_json, request_handler
|
from synapse.http.server import respond_with_json, request_handler
|
||||||
|
|
||||||
from synapse.util.stringutils import random_string, is_ascii
|
from synapse.util.stringutils import random_string
|
||||||
from synapse.api.errors import SynapseError
|
from synapse.api.errors import SynapseError
|
||||||
|
|
||||||
from twisted.web.server import NOT_DONE_YET
|
from twisted.web.server import NOT_DONE_YET
|
||||||
@ -86,9 +86,7 @@ class UploadResource(BaseMediaResource):
|
|||||||
|
|
||||||
upload_name = request.args.get("filename", None)
|
upload_name = request.args.get("filename", None)
|
||||||
if upload_name:
|
if upload_name:
|
||||||
upload_name = upload_name[0]
|
upload_name = upload_name[0].decode('UTF-8')
|
||||||
if upload_name and not is_ascii(upload_name):
|
|
||||||
raise SynapseError(400, "filename must be ascii")
|
|
||||||
|
|
||||||
headers = request.requestHeaders
|
headers = request.requestHeaders
|
||||||
|
|
||||||
|
@ -38,6 +38,8 @@ def random_string_with_symbols(length):
|
|||||||
def is_ascii(s):
|
def is_ascii(s):
|
||||||
try:
|
try:
|
||||||
s.encode("ascii")
|
s.encode("ascii")
|
||||||
|
except UnicodeEncodeError:
|
||||||
|
return False
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user