all: rewrite the lexer to consume the entire input first

Previously we used the buffruneio package to buffer input. However,
the error handling was not good, and we would often panic when parsing
inputs.

SSH config files are generally not large, on the order of kilobytes or
megabytes, and it's fine to just read the entire thing into memory and
then parse from there. This also simplifies the parser significantly
and lets us remove a dependency and several defer calls.

Add a test that panicked with the old version and then modify the code
to ensure the test no longer panics.

Thanks to Mark Nevill (@devnev) for the initial error report and
failing test case.

Fixes #10.
Fixes #24.
This commit is contained in:
Mark Nevill
2019-06-21 12:17:37 +01:00
committed by Kevin Burke
parent 2e50c44127
commit 14846fb743
5 changed files with 60 additions and 28 deletions

View File

@@ -169,6 +169,12 @@ func (p *sshParser) parseComment() sshParserStateFn {
}
func parseSSH(flow chan token, system bool, depth uint8) *Config {
// Ensure we consume tokens to completion even if parser exits early
defer func() {
for range flow {
}
}()
result := newConfig()
result.position = Position{1, 1}
parser := &sshParser{