Fix DOS line endings parsing
Previously we would fail to lex lines ending with CRLF properly.
This commit is contained in:
committed by
Kevin Burke
parent
0ff8514904
commit
fe204ef364
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
||||
testdata/dos-lines eol=crlf
|
||||
@@ -1,2 +1,3 @@
|
||||
Eugene Terentev <eugene@terentev.net>
|
||||
Kevin Burke <kev@inburke.com>
|
||||
Sergey Lukjanov <me@slukjanov.name>
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
6
lexer.go
6
lexer.go
@@ -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
10
testdata/dos-lines
vendored
Normal 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
|
||||
Reference in New Issue
Block a user