Don't parse a block begin while inside a block

If a PEM contained anything like <foobar>, the parser was doomed.

Fixes #78
This commit is contained in:
Davide De Rosa 2019-04-02 19:07:48 +02:00
parent d22420c06b
commit ccb6329f05

View File

@ -187,14 +187,16 @@ public class ConfigurationParser {
} }
if unsupportedError == nil { if unsupportedError == nil {
Regex.blockBegin.enumerateComponents(in: line) { if currentBlockName == nil {
isHandled = true Regex.blockBegin.enumerateComponents(in: line) {
let tag = $0.first! isHandled = true
let from = tag.index(after: tag.startIndex) let tag = $0.first!
let to = tag.index(before: tag.endIndex) let from = tag.index(after: tag.startIndex)
let to = tag.index(before: tag.endIndex)
currentBlockName = String(tag[from..<to]) currentBlockName = String(tag[from..<to])
currentBlock = [] currentBlock = []
}
} }
Regex.blockEnd.enumerateComponents(in: line) { Regex.blockEnd.enumerateComponents(in: line) {
isHandled = true isHandled = true