From 22b5b6b0938941255b0a1da9427c92ce3be46864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Estrela?= Date: Mon, 12 Aug 2024 21:36:05 +0100 Subject: [PATCH] fix: split yaml by matching (?m)^---\n regex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Estrela --- internal/manifests/manifests.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/manifests/manifests.go b/internal/manifests/manifests.go index d6dbb15..db0841a 100644 --- a/internal/manifests/manifests.go +++ b/internal/manifests/manifests.go @@ -4,6 +4,7 @@ import ( "bytes" "errors" "fmt" + "regexp" "strings" "github.com/ghodss/yaml" @@ -27,9 +28,11 @@ func CombineYAML(manifests [][]byte) []byte { } func SplitYAML(manifest []byte) (map[string][]byte, error) { - manifests := bytes.Split(manifest, []byte("---\n")) + separator := regexp.MustCompile(`(?m)^---\n`) + manifests := separator.Split(string(manifest), -1) manifestsByResourceTypeAndName := map[string][]byte{} - for _, manifest = range manifests { + for _, manifestStr := range manifests { + manifest := []byte(manifestStr) resource := struct { Kind string `json:"kind"` Metadata struct {