|
1 |
| -# -*- coding: utf-8 -*- |
2 |
| - |
| 1 | +from odoo.http import content_disposition |
3 | 2 | from odoo.tests import common
|
4 | 3 | import odoo
|
5 | 4 |
|
@@ -154,3 +153,30 @@ def test_ir_http_public_user_image(self):
|
154 | 153 | public_user = self.env.ref('base.public_user')
|
155 | 154 | code, *_ = self.env['ir.http']._binary_record_content(public_user.with_user(public_user), 'image_128')
|
156 | 155 | self.assertEqual(code, 404)
|
| 156 | + |
| 157 | + |
| 158 | +class TestContentDisposition(common.BaseCase): |
| 159 | + |
| 160 | + def test_content_disposition(self): |
| 161 | + """ Test that content_disposition filename conforms to RFC 6266, RFC 5987 """ |
| 162 | + assertions = [ |
| 163 | + ('foo bar.xls', 'foo%20bar.xls', 'Space character'), |
| 164 | + ('foo(bar).xls', 'foo%28bar%29.xls', 'Parenthesis'), |
| 165 | + ('foo<bar>.xls', 'foo%3Cbar%3E.xls', 'Angle brackets'), |
| 166 | + ('foo[bar].xls', 'foo%5Bbar%5D.xls', 'Brackets'), |
| 167 | + ('foo{bar}.xls', 'foo%7Bbar%7D.xls', 'Curly brackets'), |
| 168 | + ( '[email protected]', 'foo%40bar.xls', 'At sign'), |
| 169 | + ('foo,bar.xls', 'foo%2Cbar.xls', 'Comma sign'), |
| 170 | + ('foo;bar.xls', 'foo%3Bbar.xls', 'Semicolon sign'), |
| 171 | + ('foo:bar.xls', 'foo%3Abar.xls', 'Colon sign'), |
| 172 | + ('foo\\bar.xls', 'foo%5Cbar.xls', 'Backslash sign'), |
| 173 | + ('foo"bar.xls', 'foo%22bar.xls', 'Double quote sign'), |
| 174 | + ('foo/bar.xls', 'foo%2Fbar.xls', 'Slash sign'), |
| 175 | + ('foo?bar.xls', 'foo%3Fbar.xls', 'Question mark'), |
| 176 | + ('foo=bar.xls', 'foo%3Dbar.xls', 'Equal sign'), |
| 177 | + ('foo*bar.xls', 'foo%2Abar.xls', 'Star sign'), |
| 178 | + ("foo'bar.xls", 'foo%27bar.xls', 'Single-quote sign'), |
| 179 | + ('foo%bar.xls', 'foo%25bar.xls', 'Percent sign'), |
| 180 | + ] |
| 181 | + for filename, pct_encoded, hint in assertions: |
| 182 | + self.assertEqual(content_disposition(filename), f"attachment; filename*=UTF-8''{pct_encoded}", f'{hint} should be percent encoded') |
0 commit comments