From 03efb0dbc915318da90fa88011bdb8f12cd3688c Mon Sep 17 00:00:00 2001 From: fsc-eriker <72394365+fsc-eriker@users.noreply.github.com> Date: Wed, 14 Feb 2024 16:27:51 +0200 Subject: [PATCH] Update for GH-104802: don't register dot defect if there is a single cwf Don't add new error cases when refactoring; simply ensure that the code avoids an IndexError for the cases it attempts to handle --- Lib/email/_header_value_parser.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py index c448fd07dfcca1..ce4776cfc3e20a 100644 --- a/Lib/email/_header_value_parser.py +++ b/Lib/email/_header_value_parser.py @@ -1519,14 +1519,14 @@ def get_obs_local_part(value): else: if (obs_local_part[0].token_type == 'dot' or (obs_local_part[0].token_type=='cfws' - and len(obs_local_part) == 1 - or obs_local_part[1].token_type=='dot')): + and len(obs_local_part) > 1 + and obs_local_part[1].token_type=='dot')): obs_local_part.defects.append(errors.InvalidHeaderDefect( "Invalid leading '.' in local part")) if (obs_local_part[-1].token_type == 'dot' or (obs_local_part[-1].token_type=='cfws' - and len(obs_local_part) == 1 - or obs_local_part[-2].token_type=='dot')): + and len(obs_local_part) > 1 + and obs_local_part[-2].token_type=='dot')): obs_local_part.defects.append(errors.InvalidHeaderDefect( "Invalid trailing '.' in local part")) if obs_local_part.defects: