Correctly parse files without trailing newline

If the file did not have a newline character as the last character,
parseKV() would panic with an NPE. Handle the parser changes better.

Fixes #21.
This commit is contained in:
Kevin Burke
2018-08-30 12:02:32 -06:00
parent 82cf3f9264
commit 555f37af0a
3 changed files with 22 additions and 0 deletions

View File

@@ -96,6 +96,9 @@ func (p *sshParser) parseKV() sshParserStateFn {
}
comment := ""
tok := p.peek()
if tok == nil {
tok = &token{typ: tokenEOF}
}
if tok.typ == tokenComment && tok.Position.Line == val.Position.Line {
tok = p.getToken()
comment = tok.val