From fc03c635c1e85b306c456cd9517201d05bf3d187 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Tue, 8 Jan 2019 19:28:38 +0530 Subject: Parsing: Error on duplicate entries Signed-off-by: Roopesh Chander --- WireGuard/Shared/Model/TunnelConfiguration+WgQuickConfig.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'WireGuard/Shared/Model') diff --git a/WireGuard/Shared/Model/TunnelConfiguration+WgQuickConfig.swift b/WireGuard/Shared/Model/TunnelConfiguration+WgQuickConfig.swift index e438e29..48c88b0 100644 --- a/WireGuard/Shared/Model/TunnelConfiguration+WgQuickConfig.swift +++ b/WireGuard/Shared/Model/TunnelConfiguration+WgQuickConfig.swift @@ -30,6 +30,7 @@ extension TunnelConfiguration { case peerHasInvalidPersistentKeepAlive(String) case peerHasUnrecognizedKey(String) case multiplePeersWithSamePublicKey + case multipleEntriesForKey(String) } //swiftlint:disable:next function_body_length cyclomatic_complexity @@ -61,8 +62,12 @@ extension TunnelConfiguration { let key = keyWithCase.lowercased() let value = line[line.index(equalsIndex, offsetBy: 1)...].trimmingCharacters(in: .whitespaces) let keysWithMultipleEntriesAllowed: Set = ["address", "allowedips", "dns"] - if let presentValue = attributes[key], keysWithMultipleEntriesAllowed.contains(key) { - attributes[key] = presentValue + "," + value + if let presentValue = attributes[key] { + if keysWithMultipleEntriesAllowed.contains(key) { + attributes[key] = presentValue + "," + value + } else { + throw ParseError.multipleEntriesForKey(keyWithCase) + } } else { attributes[key] = value } -- cgit v1.2.3-59-g8ed1b