Skip to content

Commit

Permalink
include check for wrong formatted commit. Closes #79
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Marin committed Aug 24, 2022
1 parent 477768c commit 8c0cb76
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,13 @@ func parseRouteLine(str string) (*types.Route, bool) {
}

ip := net.ParseIP(p[i])
hostnames := p[i+1:]

if ip == nil {
if ip == nil || len(hostnames) == 0 {
return nil, false
}

return &types.Route{IP: ip, HostNames: p[i+1:]}, true
return &types.Route{IP: ip, HostNames: hostnames}, true
}

// ParseProfile creates a new profile reading lines from a reader.
Expand Down
16 changes: 16 additions & 0 deletions pkg/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ func TestHostFile(t *testing.T) {
})
}

func TestWrongHostFile(t *testing.T) {
testFile := `
# This file should be parsed as comment
# 1.1.1.1
`

t.Run("Wrong Content", func(t *testing.T) {
f := strings.NewReader(testFile)

data, err := Parse(f)
assert.NoError(t, err)
assert.Len(t, data.ProfileNames, 0)
assert.Equal(t, data.DefaultProfile[2].Comment, "# 1.1.1.1")
})
}

func appendLine(p *types.Profile, line string) {
if line == "" {
return
Expand Down

0 comments on commit 8c0cb76

Please sign in to comment.