Fix DOS line endings parsing

Previously we would fail to lex lines ending with CRLF properly.
This commit is contained in:
Eugene Terentev
2018-03-04 20:35:48 +02:00
committed by Kevin Burke
parent 0ff8514904
commit fe204ef364
5 changed files with 42 additions and 0 deletions

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
testdata/dos-lines eol=crlf

View File

@@ -1,2 +1,3 @@
Eugene Terentev <eugene@terentev.net>
Kevin Burke <kev@inburke.com>
Sergey Lukjanov <me@slukjanov.name>

View File

@@ -338,3 +338,27 @@ func TestIndexInRange(t *testing.T) {
t.Errorf("expected User to be %q, got %q", "root", user)
}
}
func TestDosLinesEndingsDecode(t *testing.T) {
us := &UserSettings{
userConfigFinder: testConfigFinder("testdata/dos-lines"),
}
user, err := us.GetStrict("wap", "User")
if err != nil {
t.Fatal(err)
}
if user != "root" {
t.Errorf("expected User to be %q, got %q", "root", user)
}
host, err := us.GetStrict("wap2", "HostName")
if err != nil {
t.Fatal(err)
}
if host != "8.8.8.8" {
t.Errorf("expected HostName to be %q, got %q", "8.8.8.8", host)
}
}

View File

@@ -86,6 +86,12 @@ func (s *sshLexer) lexRvalue() sshLexStateFn {
for {
next := s.peek()
switch next {
case '\r':
if s.follow("\r\n") {
s.emitWithValue(tokenString, growingString)
s.skip()
return s.lexVoid
}
case '\n':
s.emitWithValue(tokenString, growingString)
s.skip()

10
testdata/dos-lines vendored Normal file
View File

@@ -0,0 +1,10 @@
# Config file with dos line endings
Host wap
HostName wap.example.org
Port 22
User root
KexAlgorithms diffie-hellman-group1-sha1
Host wap2
HostName 8.8.8.8
User google