diff --git a/Passepartout/Sources/Utils.swift b/Passepartout/Sources/Utils.swift index f4a46423..0c178870 100644 --- a/Passepartout/Sources/Utils.swift +++ b/Passepartout/Sources/Utils.swift @@ -191,3 +191,13 @@ extension StringProtocol where Index == String.Index { return NSRange(range, in: self) } } + +extension String { + func trimmedLines() -> [String] { + return components(separatedBy: .newlines).map { + $0.trimmingCharacters(in: .whitespacesAndNewlines) + }.filter { + !$0.isEmpty + } + } +} diff --git a/Passepartout/Sources/VPN/TunnelKitProvider+FileConfiguration.swift b/Passepartout/Sources/VPN/TunnelKitProvider+FileConfiguration.swift index dcd4a56a..66a0152d 100644 --- a/Passepartout/Sources/VPN/TunnelKitProvider+FileConfiguration.swift +++ b/Passepartout/Sources/VPN/TunnelKitProvider+FileConfiguration.swift @@ -59,8 +59,7 @@ extension TunnelKitProvider.Configuration { } static func parsed(from url: URL) throws -> (String, TunnelKitProvider.Configuration) { - let content = try String(contentsOf: url) - let lines = content.components(separatedBy: .newlines).map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }.filter { !$0.isEmpty } + let lines = try String(contentsOf: url).trimmedLines() var defaultProto: TunnelKitProvider.SocketType? var defaultPort: UInt16?