Skip to content

Commit

Permalink
fix: yaml doc split func and add more unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Sep 3, 2024
1 parent 9d66c43 commit 851617c
Show file tree
Hide file tree
Showing 2 changed files with 726 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pkg/yaml/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,8 @@ func SplitDocuments(s string) ([]string, error) {
return nil, fmt.Errorf("invalid document separator: %s", strings.TrimSpace(separator))
}
// Remove all whitespace
result := strings.Map(func(r rune) rune {
if unicode.IsSpace(r) {
return -1
}
return r
}, s[prev:loc[0]])
if len(result) > 0 {
result := s[prev:loc[0]]
if len(result) > 0 && !isAllWhitespace(result) {
docs = append(docs, result)
}
prev = loc[1]
Expand All @@ -43,3 +38,12 @@ func SplitDocuments(s string) ([]string, error) {
}
return docs, nil
}

func isAllWhitespace(str string) bool {
for _, r := range str {
if !unicode.IsSpace(r) {
return false
}
}
return true
}
Loading

0 comments on commit 851617c

Please sign in to comment.