Skip to content

Commit 31e4f3e

Browse files
committed
pythongh-127794: Coverge all the validations into a single regex
1 parent 53bdb4f commit 31e4f3e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Lib/email/_policybase.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ def __add__(self, other):
9292

9393
def validate_header(name, value):
9494
# Validate header name according to RFC 5322
95-
if not name or ' ' in name or '\t' in name or ':' in name:
95+
import re
96+
if not re.match(r'^[^\s:]+$', name):
9697
raise ValueError(f"Invalid header field name {name!r}")
9798
# Only allow printable ASCII characters
9899
if any(ord(c) < 33 or ord(c) > 126 for c in name):

0 commit comments

Comments
 (0)