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
5e477c1d
Unverified
Commit
5e477c1d
authored
5 years ago
by
The Stranjer
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Set charset to utf-8 when adding headers for certain text content types (#7044)
Fixes #7043
parent
7581d30e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
changelog.d/7044.bugfix
+1
-0
1 addition, 0 deletions
changelog.d/7044.bugfix
synapse/rest/media/v1/_base.py
+24
-1
24 additions, 1 deletion
synapse/rest/media/v1/_base.py
with
25 additions
and
1 deletion
changelog.d/7044.bugfix
0 → 100644
+
1
−
0
View file @
5e477c1d
Fix a bug that renders UTF-8 text files incorrectly when loaded from media. Contributed by @TheStranjer.
This diff is collapsed.
Click to expand it.
synapse/rest/media/v1/_base.py
+
24
−
1
View file @
5e477c1d
...
...
@@ -30,6 +30,22 @@ from synapse.util.stringutils import is_ascii
logger
=
logging
.
getLogger
(
__name__
)
# list all text content types that will have the charset default to UTF-8 when
# none is given
TEXT_CONTENT_TYPES
=
[
"
text/css
"
,
"
text/csv
"
,
"
text/html
"
,
"
text/calendar
"
,
"
text/plain
"
,
"
text/javascript
"
,
"
application/json
"
,
"
application/ld+json
"
,
"
application/rtf
"
,
"
image/svg+xml
"
,
"
text/xml
"
,
]
def
parse_media_id
(
request
):
try
:
...
...
@@ -96,7 +112,14 @@ def add_file_headers(request, media_type, file_size, upload_name):
def
_quote
(
x
):
return
urllib
.
parse
.
quote
(
x
.
encode
(
"
utf-8
"
))
request
.
setHeader
(
b
"
Content-Type
"
,
media_type
.
encode
(
"
UTF-8
"
))
# Default to a UTF-8 charset for text content types.
# ex, uses UTF-8 for 'text/css' but not 'text/css; charset=UTF-16'
if
media_type
.
lower
()
in
TEXT_CONTENT_TYPES
:
content_type
=
media_type
+
"
; charset=UTF-8
"
else
:
content_type
=
media_type
request
.
setHeader
(
b
"
Content-Type
"
,
content_type
.
encode
(
"
UTF-8
"
))
if
upload_name
:
# RFC6266 section 4.1 [1] defines both `filename` and `filename*`.
#
...
...
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