Skip to content

Commit caf53ac

Browse files
Fix overly permissive regular expression. (#21777)
1 parent 8c0f867 commit caf53ac

File tree

6 files changed

+8
-6
lines changed

6 files changed

+8
-6
lines changed

modules/openapi-generator/src/main/resources/python/api_client.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ class ApiClient:
420420
data = json.loads(response_text)
421421
except ValueError:
422422
data = response_text
423-
elif re.match(r'^application/(json|[\w!#$&.+-^_]+\+json)\s*(;|$)', content_type, re.IGNORECASE):
423+
elif re.match(r'^application/(json|[\w!#$&.+\-^_]+\+json)\s*(;|$)', content_type, re.IGNORECASE):
424424
if response_text == "":
425425
data = ""
426426
else:

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def deserialize(self, response_text: str, response_type: str, content_type: Opti
412412
data = json.loads(response_text)
413413
except ValueError:
414414
data = response_text
415-
elif re.match(r'^application/(json|[\w!#$&.+-^_]+\+json)\s*(;|$)', content_type, re.IGNORECASE):
415+
elif re.match(r'^application/(json|[\w!#$&.+\-^_]+\+json)\s*(;|$)', content_type, re.IGNORECASE):
416416
if response_text == "":
417417
data = ""
418418
else:

samples/client/echo_api/python/openapi_client/api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def deserialize(self, response_text: str, response_type: str, content_type: Opti
412412
data = json.loads(response_text)
413413
except ValueError:
414414
data = response_text
415-
elif re.match(r'^application/(json|[\w!#$&.+-^_]+\+json)\s*(;|$)', content_type, re.IGNORECASE):
415+
elif re.match(r'^application/(json|[\w!#$&.+\-^_]+\+json)\s*(;|$)', content_type, re.IGNORECASE):
416416
if response_text == "":
417417
data = ""
418418
else:

samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def deserialize(self, response_text: str, response_type: str, content_type: Opti
414414
data = json.loads(response_text)
415415
except ValueError:
416416
data = response_text
417-
elif re.match(r'^application/(json|[\w!#$&.+-^_]+\+json)\s*(;|$)', content_type, re.IGNORECASE):
417+
elif re.match(r'^application/(json|[\w!#$&.+\-^_]+\+json)\s*(;|$)', content_type, re.IGNORECASE):
418418
if response_text == "":
419419
data = ""
420420
else:

samples/openapi3/client/petstore/python/petstore_api/api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def deserialize(self, response_text: str, response_type: str, content_type: Opti
411411
data = json.loads(response_text)
412412
except ValueError:
413413
data = response_text
414-
elif re.match(r'^application/(json|[\w!#$&.+-^_]+\+json)\s*(;|$)', content_type, re.IGNORECASE):
414+
elif re.match(r'^application/(json|[\w!#$&.+\-^_]+\+json)\s*(;|$)', content_type, re.IGNORECASE):
415415
if response_text == "":
416416
data = ""
417417
else:

samples/openapi3/client/petstore/python/tests/test_deserialization.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,5 +342,7 @@ def test_deserialize_content_type(self):
342342

343343
with self.assertRaises(petstore_api.ApiException) as cm:
344344
deserialized = self.deserialize(response, "Dict[str, str]", 'application/jsonnnnn')
345-
345+
346+
with self.assertRaises(petstore_api.ApiException) as cm:
347+
deserialized = self.deserialize(response, "Dict[str, str]", 'application/<+json')
346348

0 commit comments

Comments
 (0)