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:
24
parser_test.go
Normal file
24
parser_test.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package ssh_config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type errReader struct {
|
||||
}
|
||||
|
||||
func (b *errReader) Read(p []byte) (n int, err error) {
|
||||
return 0, errors.New("read error occurred")
|
||||
}
|
||||
|
||||
func TestIOError(t *testing.T) {
|
||||
buf := &errReader{}
|
||||
_, err := Decode(buf)
|
||||
if err == nil {
|
||||
t.Fatal("expected non-nil err, got nil")
|
||||
}
|
||||
if err.Error() != "read error occurred" {
|
||||
t.Errorf("expected read error msg, got %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user