From 3aeed557648ca5ade6165c0ea896c3e58353518f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nshimiyimana=20S=C3=A9na?= Date: Thu, 29 Dec 2022 14:21:48 +0000 Subject: [PATCH] [FIX] tools: recognize SVG with explicit namespace Currently, odoo's mimetype guesser does not recognize SVGs with explicit namespace. closes odoo/odoo#108938 X-original-commit: a1257cad9d5a63d940da041f355c13ea3eba90ce Signed-off-by: Julien Castiaux --- odoo/addons/base/tests/test_mimetypes.py | 6 ++++++ odoo/tools/mimetypes.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/tests/test_mimetypes.py b/odoo/addons/base/tests/test_mimetypes.py index 7c5738d55ab..fc393627c1a 100644 --- a/odoo/addons/base/tests/test_mimetypes.py +++ b/odoo/addons/base/tests/test_mimetypes.py @@ -22,6 +22,9 @@ AA/9oACAECAQE/AX//xAAUEAEAAAAAAAAAAAAAAAAAAAAA/9oACAEBAAY/An//xAAUEAEAAAAAAAAAAA AE/IX//2gAMAwEAAgADAAAAEB//xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oACAEDAQE/EH//xAAUEQEAAAAAAAAAAAAAAAAAAAAA /9oACAECAQE/EH//xAAUEAEAAAAAAAAAAAAAAAAAAAAA/9oACAEBAAE/EH//2Q==""" SVG = b"""PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/PjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMjAwMDExMDIvL0VOIlxuICJodHRwOi8vd3d3LnczLm9yZy9UUi8yMDAwL0NSLVNWRy0yMDAwMTEwMi9EVEQvc3ZnLTIwMDAxMTAyLmR0ZCI+PHN2ZyB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIj48ZyB0cmFuc2Zvcm09InRyYW5zbGF0ZSg1MCw1MCkiPjxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxNTAiIGhlaWdodD0iNTAiIHN0eWxlPSJmaWxsOnJlZDsiIC8+PC9nPjwvc3ZnPg==""" +NAMESPACED_SVG = b""" + +""" # minimal zip file with an empty `t.txt` file ZIP = b"""UEsDBBQACAAIAGFva1AAAAAAAAAAAAAAAAAFACAAdC50eHRVVA0AB5bgaF6W4GheluBoXnV4CwABBOgDAAAE6AMAAA MAUEsHCAAAAAACAAAAAAAAAFBLAQIUAxQACAAIAGFva1AAAAAAAgAAAAAAAAAFACAAAAAAAAAAAACkgQAAAAB0LnR4dFVUDQAHlu @@ -93,6 +96,9 @@ class test_guess_mimetype(BaseCase): content = base64.b64decode(SVG) mimetype = guess_mimetype(content, default='test') self.assertTrue(mimetype.startswith('image/svg')) + + mimetype = guess_mimetype(NAMESPACED_SVG, default='test') + self.assertTrue(mimetype.startswith('image/svg')) # Tests that whitespace padded SVG are not detected as SVG in odoo implementation if not magic: mimetype = guess_mimetype(b" " + content, default='test') diff --git a/odoo/tools/mimetypes.py b/odoo/tools/mimetypes.py index fe4c503bdda..862c8c06ce7 100644 --- a/odoo/tools/mimetypes.py +++ b/odoo/tools/mimetypes.py @@ -107,7 +107,7 @@ def _check_olecf(data): def _check_svg(data): """This simply checks the existence of the opening and ending SVG tags""" - if b'' in data: + if b'