From 1051a8dc52e3aedad630e51ed2f2fe352eb0e868 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Mon, 1 May 2023 11:44:41 +0200 Subject: [PATCH] Revisit domain name validators (#297) - Allow TLDs longer than 6 characters - Allow wildcards in proxy bypass domains --- CHANGELOG.md | 6 ++++++ Passepartout/App/Constants/Theme.swift | 6 ++++++ Passepartout/App/Reusable/Validators.swift | 14 ++++++++++++-- Passepartout/App/Views/NetworkSettingsView.swift | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9b7d6bf..b3966afa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- Allow wildcards in proxy bypass domains. [#296](https://github.com/passepartoutvpn/passepartout-apple/issues/296) + ## 2.1.1 (2023-04-19) ### Added diff --git a/Passepartout/App/Constants/Theme.swift b/Passepartout/App/Constants/Theme.swift index 96cf8a5b..e30d281c 100644 --- a/Passepartout/App/Constants/Theme.swift +++ b/Passepartout/App/Constants/Theme.swift @@ -546,6 +546,12 @@ extension View { .themeRawTextStyle() } + func themeValidWildcardDomainName(_ domainName: String?) -> some View { + themeValidating(domainName, validator: Validators.wildcardDomainName) + .keyboardType(.asciiCapable) + .themeRawTextStyle() + } + func themeValidDNSOverTLSServerName(_ string: String?) -> some View { themeValidating(string, validator: Validators.dnsOverTLSServerName) .keyboardType(.asciiCapable) diff --git a/Passepartout/App/Reusable/Validators.swift b/Passepartout/App/Reusable/Validators.swift index ff7904d7..a1d4f5ad 100644 --- a/Passepartout/App/Reusable/Validators.swift +++ b/Passepartout/App/Reusable/Validators.swift @@ -35,9 +35,15 @@ struct Validators { case domainName + case wildcardDomainName + case url } + private static let rxDomainName = NSRegularExpression("^((?!-)[A-Za-z0-9-]{1,63}(? 0 else { throw ValidationError.domainName } } + static func wildcardDomainName(_ string: String) throws { + guard rxWildcardDomainName.numberOfMatches(in: string, options: [], range: .init(location: 0, length: string.count)) > 0 else { + throw ValidationError.wildcardDomainName + } + } + static func url(_ string: String) throws { guard URL(string: string) != nil else { throw ValidationError.url diff --git a/Passepartout/App/Views/NetworkSettingsView.swift b/Passepartout/App/Views/NetworkSettingsView.swift index 7c5ce1d3..6c80541a 100644 --- a/Passepartout/App/Views/NetworkSettingsView.swift +++ b/Passepartout/App/Views/NetworkSettingsView.swift @@ -261,7 +261,7 @@ extension NetworkSettingsView { text: $0.text, onEditingChanged: $0.onEditingChanged, onCommit: $0.onCommit - ).themeValidDomainName($0.text.wrappedValue) + ).themeValidWildcardDomainName($0.text.wrappedValue) } addLabel: { Text(L10n.NetworkSettings.Items.AddProxyBypass.caption) } commitLabel: {