Config file parsing: Fix bug when there are comments at the end

This commit is contained in:
Roopesh Chander 2019-01-24 16:23:07 +05:30
parent 8c4475111b
commit e95cb6e6bd
1 changed files with 28 additions and 28 deletions

View File

@ -54,10 +54,9 @@ extension TunnelConfiguration {
} }
trimmedLine = trimmedLine.trimmingCharacters(in: .whitespaces) trimmedLine = trimmedLine.trimmingCharacters(in: .whitespaces)
let lowercasedLine = trimmedLine.lowercased()
guard !trimmedLine.isEmpty else { continue } if !trimmedLine.isEmpty {
let lowercasedLine = line.lowercased()
if let equalsIndex = line.firstIndex(of: "=") { if let equalsIndex = line.firstIndex(of: "=") {
// Line contains an attribute // Line contains an attribute
let keyWithCase = line[..<equalsIndex].trimmingCharacters(in: .whitespaces) let keyWithCase = line[..<equalsIndex].trimmingCharacters(in: .whitespaces)
@ -87,6 +86,7 @@ extension TunnelConfiguration {
} else if lowercasedLine != "[interface]" && lowercasedLine != "[peer]" { } else if lowercasedLine != "[interface]" && lowercasedLine != "[peer]" {
throw ParseError.invalidLine(line) throw ParseError.invalidLine(line)
} }
}
let isLastLine = lineIndex == lines.count - 1 let isLastLine = lineIndex == lines.count - 1