Skip to content

Commit

Permalink
Fix out of range panics (#182)
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Novikov <novikov.dmitri.a@gmail.com>
  • Loading branch information
dnovikoff committed Feb 19, 2024
1 parent 667afeb commit 5ae85f3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/gci/testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,26 @@ import (
testing "github.com/daixiang0/test"
g "github.com/golang"
)
`,
},
{
"no-trailing-newline",

`sections:
- Standard
`,
`package main
import (
"net"
"fmt"
)`,
`package main
import (
"fmt"
"net"
)
`,
},
}
3 changes: 3 additions & 0 deletions pkg/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ func ParseFile(src []byte, filename string) (ImportList, int, int, int, int, err
headEnd = int(decl.Pos()) - 1
}
tailStart = int(decl.End())
if tailStart > len(src) {
tailStart = len(src)
}

for _, spec := range genDecl.Specs {
imp := spec.(*ast.ImportSpec)
Expand Down

0 comments on commit 5ae85f3

Please sign in to comment.