@@ -322,15 +322,17 @@ def validate_email_domain_name(domain, test_environment=False, globally_delivera
322
322
323
323
# Perform UTS-46 normalization, which includes casefolding, NFC normalization,
324
324
# and converting all label separators (the period/full stop, fullwidth full stop,
325
- # ideographic full stop, and halfwidth ideographic full stop) to basic periods .
325
+ # ideographic full stop, and halfwidth ideographic full stop) to regular dots .
326
326
# It will also raise an exception if there is an invalid character in the input,
327
- # such as "⒈" which is invalid because it would expand to include a period.
327
+ # such as "⒈" which is invalid because it would expand to include a dot.
328
+ # Since several characters are normalized to a dot, this has to come before
329
+ # checks related to dots, like check_dot_atom which comes next.
328
330
try :
329
331
domain = idna .uts46_remap (domain , std3_rules = False , transitional = False )
330
332
except idna .IDNAError as e :
331
333
raise EmailSyntaxError (f"The part after the @-sign contains invalid characters ({ e } )." )
332
334
333
- # The domain part is made up period -separated "labels." Each label must
335
+ # The domain part is made up dot -separated "labels." Each label must
334
336
# have at least one character and cannot start or end with dashes, which
335
337
# means there are some surprising restrictions on periods and dashes.
336
338
# Check that before we do IDNA encoding because the IDNA library gives
@@ -362,6 +364,8 @@ def validate_email_domain_name(domain, test_environment=False, globally_delivera
362
364
# For ASCII-only domains, the transformation does nothing and is safe to
363
365
# apply. However, to ensure we don't rely on the idna library for basic
364
366
# syntax checks, we don't use it if it's not needed.
367
+ #
368
+ # uts46 is off here because it is handled above.
365
369
try :
366
370
ascii_domain = idna .encode (domain , uts46 = False ).decode ("ascii" )
367
371
except idna .IDNAError as e :
@@ -371,6 +375,9 @@ def validate_email_domain_name(domain, test_environment=False, globally_delivera
371
375
# one the user supplied. Also I'm not sure if the length check applies
372
376
# to the internationalized form, the IDNA ASCII form, or even both!
373
377
raise EmailSyntaxError ("The email address is too long after the @-sign." )
378
+
379
+ # Other errors seem to not be possible because the call to idna.uts46_remap
380
+ # would have already raised them.
374
381
raise EmailSyntaxError (f"The part after the @-sign contains invalid characters ({ e } )." )
375
382
376
383
# Check the syntax of the string returned by idna.encode.
0 commit comments