Skip to content

Commit

Permalink
Fix DOS line endings parsing
Browse files Browse the repository at this point in the history
Previously we would fail to lex lines ending with CRLF properly.
  • Loading branch information
Eugene Terentev authored and kevinburke committed Mar 17, 2018
1 parent 0ff8514 commit fe204ef
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testdata/dos-lines eol=crlf
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Eugene Terentev <[email protected]>
Kevin Burke <[email protected]>
Sergey Lukjanov <[email protected]>
24 changes: 24 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 6 additions & 0 deletions lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions testdata/dos-lines
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fe204ef

Please sign in to comment.