Fix migration of DNS settings (#1144)

In some cases, the migration process may insert a DNS module without
servers. Do not add it at all.
This commit is contained in:
Davide 2025-02-07 01:15:03 +01:00 committed by GitHub
parent f34dcd99f8
commit e8ffca9d50
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -121,8 +121,8 @@ extension MapperV2 {
extension MapperV2 {
func toNetworkModules(_ v2: ProfileV2.NetworkSettings) throws -> [Module] {
var modules: [Module] = []
if v2.dns.choice == .manual {
modules.append(try toDNSModule(v2.dns))
if v2.dns.choice == .manual, let dnsModule = try toDNSModule(v2.dns) {
modules.append(dnsModule)
}
if v2.proxy.choice == .manual {
modules.append(try toHTTPProxyModule(v2.proxy))
@ -133,10 +133,13 @@ extension MapperV2 {
return modules
}
func toDNSModule(_ v2: Network.DNSSettings) throws -> DNSModule {
func toDNSModule(_ v2: Network.DNSSettings) throws -> DNSModule? {
var builder = DNSModule.Builder()
builder.protocolType = v2.dnsProtocol ?? .cleartext
builder.servers = v2.dnsServers ?? []
guard builder.protocolType != .cleartext || !builder.servers.isEmpty else {
return nil
}
builder.domainName = v2.dnsDomain
builder.searchDomains = v2.dnsSearchDomains
builder.dohURL = v2.dnsHTTPSURL?.absoluteString ?? ""