Skip to content

Commit

Permalink
🐛 panic against empty file with eof_newline feature, resolves: #196
Browse files Browse the repository at this point in the history
  • Loading branch information
Shion1305 committed Jul 17, 2024
1 parent 6dd7bbb commit 264fe9e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion internal/features/eof_newline.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func MakeFeatureEOFNewline(linebreakStr string) yamlfmt.Feature {
func eofNewlineFeature(linebreakStr string) yamlfmt.FeatureFunc {
return func(content []byte) ([]byte, error) {
// This check works in both linebreak modes.
if content[len(content)-1] != '\n' {
if len(content) == 0 || content[len(content)-1] != '\n' {
linebreakBytes := []byte(linebreakStr)
content = append(content, linebreakBytes...)
}
Expand Down

0 comments on commit 264fe9e

Please sign in to comment.