Skip to content

Commit 73b050e

Browse files
committed
Tighten up obs_local_part checks further to avoid IndexError
Also, reformat slightly to make the indentation more obvious
1 parent 46a84b1 commit 73b050e

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Lib/email/_header_value_parser.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,14 +1517,16 @@ def get_obs_local_part(value):
15171517
obs_local_part.defects.append(errors.InvalidHeaderDefect(
15181518
"abandoned parse; truncated value?"))
15191519
else:
1520-
if (obs_local_part[0].token_type == 'dot' or
1521-
obs_local_part[0].token_type=='cfws' and
1522-
obs_local_part[1].token_type=='dot'):
1520+
if (obs_local_part[0].token_type == 'dot'
1521+
or (obs_local_part[0].token_type=='cfws'
1522+
and len(obs_local_part) == 1
1523+
or obs_local_part[1].token_type=='dot')):
15231524
obs_local_part.defects.append(errors.InvalidHeaderDefect(
15241525
"Invalid leading '.' in local part"))
1525-
if (obs_local_part[-1].token_type == 'dot' or
1526-
obs_local_part[-1].token_type=='cfws' and
1527-
obs_local_part[-2].token_type=='dot'):
1526+
if (obs_local_part[-1].token_type == 'dot'
1527+
or (obs_local_part[-1].token_type=='cfws'
1528+
and len(obs_local_part) == 1
1529+
or obs_local_part[-2].token_type=='dot')):
15281530
obs_local_part.defects.append(errors.InvalidHeaderDefect(
15291531
"Invalid trailing '.' in local part"))
15301532
if obs_local_part.defects:

0 commit comments

Comments
 (0)