diff --git a/Modules/RSWeb/Sources/RSWeb/SpecialCases.swift b/Modules/RSWeb/Sources/RSWeb/SpecialCases.swift index a8a3181fa..46fb543de 100644 --- a/Modules/RSWeb/Sources/RSWeb/SpecialCases.swift +++ b/Modules/RSWeb/Sources/RSWeb/SpecialCases.swift @@ -25,10 +25,11 @@ nonisolated public struct SpecialCase { return false } - /// Returns true if the URL’s host matches one of the supplied domain names. + /// Returns true if the URL’s host belongs to one of the supplied domains. /// /// Unlike `urlStringContainSpecialCase`, this checks only the host component — not the path or query. /// A leading `www.` on the URL’s host is treated as optional, so `example.com` in `domains` matches a host of either `example.com` or `www.example.com`. + /// Subdomains also match: `micro.blog` in `domains` matches a host of `gruber.micro.blog`. /// The supplied `domains` are assumed to already be lowercased and to have any leading `www.` stripped. public static func urlStringMatchesDomain(_ urlString: String, _ domains: [String]) -> Bool { guard let url = URL(string: urlString), let host = url.host()?.lowercased(with: localeForLowercasing) else { @@ -36,7 +37,10 @@ nonisolated public struct SpecialCase { } let normalizedHost = stringByStrippingWWWPrefix(host) for domain in domains { - if normalizedHost == domain { + if domain.isEmpty { + continue + } + if normalizedHost == domain || normalizedHost.hasSuffix("." + domain) { return true } }