Skip to content

Commit 18af9e6

Browse files
committed
defined a constant for the "name=" literal to avoid duplication in the OpenAPI validation middleware
1 parent 65d06ef commit 18af9e6

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

aws_lambda_powertools/event_handler/middlewares/openapi_validation.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131

3232
logger = logging.getLogger(__name__)
3333

34+
# Constants
35+
CONTENT_DISPOSITION_NAME_PARAM = "name="
36+
3437

3538
class OpenAPIValidationMiddleware(BaseMiddlewareHandler):
3639
"""
@@ -401,16 +404,16 @@ def _parse_multipart_part(self, part: str) -> tuple[str | None, Any]:
401404

402405
def _extract_field_name(self, content_disposition: str) -> str | None:
403406
"""Extract field name from Content-Disposition header."""
404-
if "name=" not in content_disposition:
407+
if CONTENT_DISPOSITION_NAME_PARAM not in content_disposition:
405408
return None
406409

407410
# Handle both quoted and unquoted names
408411
if 'name="' in content_disposition:
409412
name_start = content_disposition.find('name="') + 6
410413
name_end = content_disposition.find('"', name_start)
411414
return content_disposition[name_start:name_end]
412-
elif "name=" in content_disposition:
413-
name_start = content_disposition.find("name=") + 5
415+
elif CONTENT_DISPOSITION_NAME_PARAM in content_disposition:
416+
name_start = content_disposition.find(CONTENT_DISPOSITION_NAME_PARAM) + len(CONTENT_DISPOSITION_NAME_PARAM)
414417
name_end = content_disposition.find(";", name_start)
415418
if name_end == -1:
416419
name_end = len(content_disposition)

0 commit comments

Comments
 (0)