You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix: enforce ASCII-only domain labels in .ascii compatibility mode
In .ascii mode the entire email address must be ASCII — the local-part
check already enforced this, but the domain label character set was
not gated by compatibility, silently accepting Unicode U-labels such
as 例え or 한국 even when the caller expected a fully ASCII address.
Added asciiDomainLabelCharacterSet (strict LDH: A-Z, a-z, 0-9, hyphen)
and threaded extractionCompatibility through the private mailbox and
extractHost helpers so that the appropriate set is selected per mode:
.ascii → LDH only (Punycode xn--… passes naturally)
.unicode /
.asciiWithUnicodeExtension → existing domainLabelCharacterSet
(Unicode U-labels allowed per RFC 5891)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: Tests/SwiftEmailValidatorTests/EmailSyntaxValidatorTests.swift
+24Lines changed: 24 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -140,6 +140,30 @@ final class EmailSyntaxValidatorTests: XCTestCase {
140
140
XCTAssertNil(EmailSyntaxValidator.mailbox(from:"한@x.한국", compatibility:.ascii),"Unicode in email addresses should not be allowed in ASCII compatibility mode")
141
141
XCTAssertNil(EmailSyntaxValidator.mailbox(from:"\"한\"@x.한국", compatibility:.ascii),"Unicode in email addresses should not be allowed in ASCII compatibility mode")
142
142
}
143
+
144
+
func testAsciiRejectsUnicodeDomain(){
145
+
// In .ascii mode the domain must also be ASCII-only (LDH labels or Punycode).
146
+
// A Unicode U-label like 例え or 한국 must be rejected even when the local part is ASCII.
"Unicode domain label must be accepted in .unicode mode"
165
+
)
166
+
}
143
167
144
168
func testUnicodeCompatibility(){
145
169
XCTAssertEqual(EmailSyntaxValidator.mailbox(from:"한@x.한국", compatibility:.unicode)?.localPart,.dotAtom("한"),"Unicode email addresses should be allowed in Unicode compatibility")
0 commit comments