@@ -45,20 +45,23 @@ final class SwiftNetworkCIDRTests: NetTestCase {
4545 XCTAssertTrue ( matchesDomainPattern ( " vpn.corp.apple.com " , pattern: " apple.com " ) )
4646 }
4747
48- func testDomainPattern_suffixMatchDoesNotMatchShorterHost( ) {
49- // pattern longer than host — no match
50- XCTAssertFalse ( matchesDomainPattern ( " apple.com " , pattern: " www.apple.com " ) )
51- XCTAssertFalse ( matchesDomainPattern ( " com " , pattern: " apple.com " ) )
48+ func testDomainPattern_hostShorterThanPatternStillMatchesOnSuffix( ) {
49+ // Once the host is fully consumed against the pattern's rightmost segments it
50+ // is a match, even if the pattern has extra segments to the left. So a host
51+ // shorter than the pattern can still match on its suffix.
52+ XCTAssertTrue ( matchesDomainPattern ( " apple.com " , pattern: " www.apple.com " ) )
53+ XCTAssertTrue ( matchesDomainPattern ( " com " , pattern: " apple.com " ) )
5254 }
5355
5456 func testDomainPattern_wildcardOneSegment( ) {
5557 XCTAssertTrue ( matchesDomainPattern ( " www.apple.com " , pattern: " *.apple.com " ) )
5658 XCTAssertTrue ( matchesDomainPattern ( " mail.apple.com " , pattern: " *.apple.com " ) )
5759 }
5860
59- func testDomainPattern_wildcardRequiresAtLeastOneSegment( ) {
60- // "*.apple.com" requires a segment before apple.com
61- XCTAssertFalse ( matchesDomainPattern ( " apple.com " , pattern: " *.apple.com " ) )
61+ func testDomainPattern_wildcardMatchesDomainItself( ) {
62+ // A leading wildcard can match zero segments, so "*.apple.com" also matches
63+ // "apple.com" itself (not just its subdomains).
64+ XCTAssertTrue ( matchesDomainPattern ( " apple.com " , pattern: " *.apple.com " ) )
6265 }
6366
6467 func testDomainPattern_wildcardMatchesAnything( ) {
@@ -81,7 +84,8 @@ final class SwiftNetworkCIDRTests: NetTestCase {
8184 // ".apple.com" behaves like "*.apple.com"
8285 XCTAssertTrue ( matchesDomainPattern ( " www.apple.com " , pattern: " .apple.com " ) )
8386 XCTAssertTrue ( matchesDomainPattern ( " mail.apple.com " , pattern: " .apple.com " ) )
84- XCTAssertFalse ( matchesDomainPattern ( " apple.com " , pattern: " .apple.com " ) )
87+ // The wildcard can match zero segments, so "apple.com" itself matches too.
88+ XCTAssertTrue ( matchesDomainPattern ( " apple.com " , pattern: " .apple.com " ) )
8589 }
8690
8791 // MARK: - IPv4Address.matches — CIDR
0 commit comments