Skip to content

Commit

Permalink
Fix for bug of the function is_json_mimetype() (#1541)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
jacobstanly89 and Ruwann authored May 31, 2022
1 parent be492f9 commit b561ecf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions connexion/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))


Expand Down
8 changes: 8 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

0 comments on commit b561ecf

Please sign in to comment.