This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix parsing of Content-Disposition headers (#4763)
* Fix parsing of Content-Disposition headers TIL: filenames in content-dispostion headers can contain semicolons, and aren't %-encoded. * fix python2 incompatibility * Fix docstrings
- v1.98.0
- v1.98.0rc1
- v1.97.0
- v1.97.0rc1
- v1.96.1
- v1.96.0
- v1.96.0rc1
- v1.95.1
- v1.95.0
- v1.95.0rc1
- v1.94.0
- v1.94.0rc1
- v1.93.0
- v1.93.0rc1
- v1.92.3
- v1.92.2
- v1.92.1
- v1.92.0
- v1.92.0rc1
- v1.91.2
- v1.91.1
- v1.91.0
- v1.91.0rc1
- v1.90.0
- v1.90.0rc1
- v1.89.0
- v1.89.0rc1
- v1.88.0
- v1.88.0rc1
- v1.87.0
- v1.87.0rc1
- v1.86.0
- v1.86.0rc2
- v1.86.0rc1
- v1.85.2
- v1.85.1
- v1.85.0
- v1.85.0rc2
- v1.85.0rc1
- v1.84.1
- v1.84.0
- v1.84.0rc1
- v1.83.0
- v1.83.0rc1
- v1.82.0
- v1.82.0rc1
- v1.81.0
- v1.81.0rc2
- v1.81.0rc1
- v1.80.0
- v1.80.0rc2
- v1.80.0rc1
- v1.79.0
- v1.79.0rc2
- v1.79.0rc1
- v1.78.0
- v1.78.0rc1
- v1.77.0
- v1.77.0rc2
- v1.77.0rc1
- v1.76.0
- v1.76.0rc2
- v1.76.0rc1
- v1.75.0
- v1.75.0rc2
- v1.75.0rc1
- v1.74.0
- v1.74.0rc1
- v1.73.0
- v1.73.0rc2
- v1.73.0rc1
- v1.72.0
- v1.72.0rc1
- v1.71.0
- v1.71.0rc2
- v1.71.0rc1
- v1.70.1
- v1.70.0
- v1.70.0rc2
- v1.70.0rc1
- v1.69.0
- v1.69.0rc4
- v1.69.0rc3
- v1.69.0rc2
- v1.69.0rc1
- v1.68.0
- v1.68.0rc2
- v1.68.0rc1
- v1.67.0
- v1.67.0rc1
- v1.66.0
- v1.66.0rc2
- v1.66.0rc1
- v1.65.0
- v1.65.0rc2
- v1.65.0rc1
- v1.65.0.post1.dev1
- v1.64.0
- v1.64.0rc2
- v1.64.0rc1
- v1.63.1
- v1.63.0
- v1.63.0rc1
- v1.62.0
- v1.62.0rc3
- v1.62.0rc2
- v1.62.0rc1
- v1.61.1
- v1.61.0
- v1.61.0rc1
- v1.60.0
- v1.60.0rc2
- v1.60.0rc1
- v1.59.1
- v1.59.0
- v1.59.0rc2
- v1.59.0rc1
- v1.58.1
- v1.58.0
- v1.58.0rc2
- v1.58.0rc1
- v1.57.1
- v1.57.0
- v1.57.0rc1
- v1.56.0
- v1.56.0rc1
- v1.55.2
- v1.55.1
- v1.55.0
- v1.55.0rc1
- v1.54.0
- v1.54.0rc1
- v1.53.0
- v1.53.0rc1
- v1.52.0
- v1.52.0rc1
- v1.51.0
- v1.51.0rc2
- v1.51.0rc1
- v1.50.2
- v1.50.1
- v1.50.0
- v1.50.0rc2
- v1.50.0rc1
- v1.49.2
- v1.49.1
- v1.49.0
- v1.49.0rc1
- v1.48.0
- v1.48.0rc1
- v1.47.1
- v1.47.0
- v1.47.0rc3
- v1.47.0rc2
- v1.47.0rc1
- v1.46.0
- v1.46.0rc1
- v1.46-modular1
- v1.45.1
- v1.45.0
- v1.45.0rc2
- v1.45.0rc1
- v1.44.0
- v1.44.0rc3
- v1.44.0rc2
- v1.44.0rc1
- v1.43.0
- v1.43.0rc2
- v1.43.0rc1
- v1.42.0
- v1.42.0rc2
- v1.42.0rc1
- v1.41.1
- v1.41.0
- v1.41.0rc1
- v1.40.0
- v1.40.0rc3
- v1.40.0rc2
- v1.40.0rc1
- v1.39.0
- v1.39.0rc3
- v1.39.0rc2
- v1.39.0rc1
- v1.38.1
- v1.38.0
- v1.38.0rc3
- v1.38.0rc2
- v1.38.0rc1
- v1.37.1
- v1.37.1rc1
- v1.37.1a1
- v1.37.0
- v1.37.0rc1
- v1.36.0
- v1.36.0rc2
- v1.36.0rc1
- v1.35.1
- v1.35.0
- v1.35.0rc3
- v1.35.0rc2
- v1.35.0rc1
- v1.34.0
- v1.34.0rc1
- v1.33.2
- v1.33.1
- v1.33.0
- v1.33.0rc2
- v1.33.0rc1
- v1.32.2
- v1.32.1
- v1.32.0
- v1.32.0rc1
- v1.31.0
- v1.31.0rc1
- v1.30.1
- v1.30.0
- v1.30.0rc1
- v1.29.0
- v1.29.0rc1
- v1.28.0
- v1.28.0rc1
- v1.27.0
- v1.27.0rc2
- v1.27.0rc1
- v1.26.0
- v1.26.0rc2
- v1.26.0rc1
- v1.26.0-deb
- v1.25.0
- v1.25.0rc1
- v1.24.0
- v1.24.0rc2
- v1.24.0rc1
- v1.23.1
- v1.23.0
- v1.23.0rc1
- v1.22.1
- v1.22.0
- v1.22.0rc2
- v1.22.0rc1
- v1.21.2
- v1.21.1
- v1.21.0
- v1.21.0rc3
- v1.21.0rc2
- v1.21.0rc1
- v1.20.1
- v1.20.0
- v1.20.0rc5
- v1.20.0rc4
- v1.20.0rc3
- v1.20.0rc2
- v1.20.0rc1
- v1.19.3
- v1.19.2
- v1.19.1
- v1.19.1rc1
- v1.19.0
- v1.19.0rc1
- v1.18.0
- v1.18.0rc2
- v1.18.0rc1
- v1.17.0
- v1.17.0rc1
- v1.17.0-mod1-modular-vdhtest2
- v1.16.1
- v1.16.0
- v1.16.0rc2
- v1.16.0rc1
- v1.15.2
- v1.15.1
- v1.15.0
- v1.15.0rc1
- v1.14.0
- v1.14.0rc2
- v1.14.0rc1
- v1.13.0
- v1.13.0rc3
- v1.13.0rc2
- v1.13.0rc1
- v1.12.4
- v1.12.4rc1
- v1.12.3
- v1.12.2
- v1.12.1
- v1.12.1rc1
- v1.12.0
- v1.12.0rc1
- v1.11.1
- v1.11.0
- v1.11.0rc1
- v1.10.1
- v1.10.0
- v1.10.0rc5
- v1.10.0rc4
- v1.10.0rc3
- v1.10.0rc2
- v1.10.0rc1
- v1.9.1
- v1.9.0
- v1.9.0rc1
- v1.9.0.dev2
- v1.9.0.dev1
- v1.8.0
- v1.8.0rc1
- v1.7.3
- v1.7.2
- v1.7.1
- v1.7.1_modular_profile_hotfix
- v1.7.0
- v1.7.0rc2
- v1.7.0rc1
- v1.6.1
- v1.6.0
- v1.6.0rc2
- v1.6.0rc1
- v1.5.1
- v1.5.1_modular_device_hotfix
- v1.5.0
- v1.5.0rc2
- v1.5.0rc1
- v1.4.1
- v1.4.1rc1
- v1.4.0
- v1.4.0rc2
- v1.4.0rc1
- v1.3.1
- v1.3.0
- v1.3.0rc1
- v1.2.1
- v1.2.0
- v1.2.0rc2
- v1.2.0rc1
- v1.1.0
- v1.1.0rc2
- v1.1.0rc1
- v1.0.0
- v1.0.0rc3
- v1.0.0rc2
- v1.0.0rc1
- v0.99.5.2
- v0.99.5.1
- v0.99.5.1.dev0
- v0.99.5
- v0.99.5rc1
- v0.99.4
- v0.99.4rc1
- v0.99.3.2
- v0.99.3.1
- v0.99.3
- v0.99.3rc1
- v0.1
- shhs-v1.2.1.2
- shhs-v1.2.1.1
- shhs-v1.2.1
- shhs-v1.2.0.2
- shhs-v1.2.0.1
- shhs-v1.2
- shhs-v1.1.1.7-opt
- shhs-v1.1.1.6-opt
- shhs-v1.1.1
- shhs-v1.1
- shhs-v1.0
- modular-dev-v1.3.2-alpha.5+modular
- modular-dev-v1.3.2-alpha.4+modular
- modular-dev-v1.3.2-alpha.3+modular
- modular-dev-v1.3.2-alpha.2+modular
- modular-dev-v1.3.2-alpha.1+modular
- hhs-9
- dinsic_2020-02-10
- dinsic_2019-08-30
- dinsic_2019-08-29
- dinsic_2019-08-12
- dinsic_2019-08-08
- dinsic_2019-07-31
- dinsic_2019-07-18
- dinsic_2019-07-09
- dinsic_2019-07-04
- dinsic_2019-06-28
- dinsic_2019-06-27_1
- dinsic_2019-06-27
- dinsic_2019-06-24
- dinsic_2019-06-19
- dinsic_2019-06-10_3
- dinsic_2019-06-10_2
- dinsic_2019-06-10
- dinsic_2019-06-04
- dinsic_2019-05-31
- dinsic_2019-05-17
- dinsic_2019-05-14
- dinsic_2019-05-09
- dinsic_2019-04-05
- dinsic_2019-04-04_2
- dinsic_2019-04-04_1
- dinsic_2019-04-04
- dinsic_2019-03-21
- 1.7.2
Showing
3 changed files
with
111 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix parsing of Content-Disposition headers on remote media requests and URL previews. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2019 New Vector Ltd | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from synapse.rest.media.v1._base import get_filename_from_headers | ||
|
||
from tests import unittest | ||
|
||
|
||
class GetFileNameFromHeadersTests(unittest.TestCase): | ||
# input -> expected result | ||
TEST_CASES = { | ||
b"inline; filename=abc.txt": u"abc.txt", | ||
b'inline; filename="azerty"': u"azerty", | ||
b'inline; filename="aze%20rty"': u"aze%20rty", | ||
b'inline; filename="aze\"rty"': u'aze"rty', | ||
b'inline; filename="azer;ty"': u"azer;ty", | ||
|
||
b"inline; filename*=utf-8''foo%C2%A3bar": u"foo£bar", | ||
} | ||
|
||
def tests(self): | ||
for hdr, expected in self.TEST_CASES.items(): | ||
res = get_filename_from_headers( | ||
{ | ||
b'Content-Disposition': [hdr], | ||
}, | ||
) | ||
self.assertEqual( | ||
res, expected, | ||
"expected output for %s to be %s but was %s" % ( | ||
hdr, expected, res, | ||
) | ||
) |