From b561ecfdaacd7606d1398512762b946e2d778c74 Mon Sep 17 00:00:00 2001 From: jacobstanly89 <105638648+jacobstanly89@users.noreply.github.com> Date: Tue, 31 May 2022 19:01:27 +0200 Subject: [PATCH] Fix for bug of the function is_json_mimetype() (#1541) * Fix for bug of the function is_json_mimetype() (#1114) * Splitting the mimetype correctly * Added a test for the json mimetype usecases * Update connexion/utils.py Co-authored-by: Ruwann --- connexion/utils.py | 3 +++ tests/test_utils.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/connexion/utils.py b/connexion/utils.py index 5a52ca801..176d847bb 100644 --- a/connexion/utils.py +++ b/connexion/utils.py @@ -136,7 +136,10 @@ def is_json_mimetype(mimetype): :type mimetype: str :rtype: bool """ + maintype, subtype = mimetype.split('/') # type: str, str + if ';' in subtype: + subtype, parameter = subtype.split(';', maxsplit=1) return maintype == 'application' and (subtype == 'json' or subtype.endswith('+json')) diff --git a/tests/test_utils.py b/tests/test_utils.py index 72c9e2774..9d6b47deb 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -60,3 +60,11 @@ def test_deep_get_dict(): def test_deep_get_list(): obj = [{'type': 'object', 'properties': {'id': {'type': 'string'}}}] assert utils.deep_get(obj, ['0', 'properties', 'id']) == {'type': 'string'} + + +def test_is_json_mimetype(): + assert utils.is_json_mimetype('application/json') + assert utils.is_json_mimetype('application/vnd.com.myEntreprise.v6+json') + assert utils.is_json_mimetype('application/vnd.scanner.adapter.vuln.report.harbor+json; version=1.0') + assert utils.is_json_mimetype('application/vnd.com.myEntreprise.v6+json; charset=UTF-8') + assert not utils.is_json_mimetype('text/html')