From 2cdff153232b80d3c491ac5eeaa3488c1c196310 Mon Sep 17 00:00:00 2001 From: Shion Ichikawa Date: Thu, 18 Jul 2024 02:39:14 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20panic=20against=20empty=20file?= =?UTF-8?q?=20with=20eof=5Fnewline=20feature,=20resolves:=20#196=20(#197)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/features/eof_newline.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/features/eof_newline.go b/internal/features/eof_newline.go index 568db9b..17e41d4 100644 --- a/internal/features/eof_newline.go +++ b/internal/features/eof_newline.go @@ -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...) }