Parser: Address, DNS and AllowedIPs can have mutliple entries

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2018-11-05 23:52:16 +05:30
parent 733c29021e
commit 34a8d70a45
1 changed files with 6 additions and 1 deletions

View File

@ -114,7 +114,12 @@ class WgQuickConfigFileParser {
// Line contains an attribute
let key = line[..<equalsIndex].trimmingCharacters(in: .whitespaces)
let value = line[line.index(equalsIndex, offsetBy: 1)...].trimmingCharacters(in: .whitespaces)
attributes[key] = value
let keysWithMultipleEntriesAllowed: Set<String> = ["Address", "AllowedIPs", "DNS"]
if let presentValue = attributes[key], keysWithMultipleEntriesAllowed.contains(key) {
attributes[key] = presentValue + "," + value
} else {
attributes[key] = value
}
} else {
if (lowercasedLine != "[interface]" && lowercasedLine != "[peer]") {
throw ParseError.invalidLine(line)